word processing with Visual Studio 2013 - vb.net

I'm new to office development and want to create a simple application that :
opens a word 2007-2010-2013 template.
reads each and every placeholder.
fills each one with the appropriate data.
However, how can I create a placeholder in a word template ?
How can I list placeholders and fill them using VB 2013 ?

Reading and writing word documents can be done in multiple ways. The easiest is probably from Inside Word itself. Microsoft provides a package called Visual Studio Tools for Office which can be used to integrate a plugin directly into word itself. You're probably looking for the Word Content Controls feature. And that could be used with XML data binding.
You can also host Word in your own application and then interact directly with the loaded document using the Office Primary Interop Assemblies. These managed classes are a wrapper around the COM objects that Office exposes. The XML data binding features are available through PIO as well. Look at the Word XML example which can be downloaded from this samples page. Primary interop assemblies are only supported in Interactive applications. Microsoft does not support running Office applications from a server/service application.
If you can limit yourself to the new XML Document standard you can extract the content from the document as XML and manipulate these directly (requires quite a bit of knowledge about the Word Document structure). The Packaging class structure provided by the .NET framework contains everything needed to extract the document parts, once extracted it's simple XML. Or you could use an open source wrapper around the XML document format, such as the open source DocX library. A template field could simply be a special text like {{TEMPLATE FIELD:FieldName}}.
There are also a number of commercial libraries available, some with built-in mail-merge features. I personally have good experience with Aspose.Words. Their documentation on Mailmerges can be found here.

Related

Is it possible to automate Visio using a third party?

We are trying to create a Visio project file and to process it with an external tool to generate a json file that a web app can read to create a decision tree based on the json contents.
We know about 3rd parties to automate MS Word files but no idea if there are others dealing with Visio files.
Google didn't return anything valid as per Automation it always returns links to how to program macros on it.
Any help will be appreciated.
There are many ways to automate Visio: macros, .net plugins, python, pascal, even windows powershell.
But if your final aim is getting Visio to the web, you may try the following link.
http://unmanagedvisio.com/category/svgexport/
The tool exports the drawing to an SVG embedded in an HTML file with Javascript functionality. Definitely worth a look.

workflow for managing help content written by external co-workers

We develop a WPF application that has something like a context sensitive help. The content of the help pages is currently written as word documents by external colleagues (say biologists) and then translated to xaml code by developers. This process is tedious and error prone because the biologists don't see the xaml code and the word documents can't easily be diffed and tracked in a version control system.
So we'd like to improve this process and maintain the content in a single place, in a format that
is simple to edit (preferrably with a wysiwyg editor),
is stored in a simple ascii format (for diffing / version control) and
can be included automatically as a resource in our C# application.
The solution could be a framework, an external tool or any other idea.
The format should support simple html rendering such as bold and italic, superscripts, etc and images.
I suggest to use Flow Documents:
It is a WPF technology so you will use the well known tool.
Flow documents can be edited in RichTextBox WPF control. You can access an edited flow document via RichTextBox.Document property. Then you can save it into XAML file with XamlWriter. Taking all this thibngs into account you can easily and quickly create a simple application for your external colleagues.
Finally, you can load saved XAML files into FlowDocumentReader control in order to display them. It is described here.
I'm not only sure if flow documents can be embedded in resources. If it is not possible, I think that help files can be distributed separately. It doesn't seem to be a big problem.
Alternatively instead of flow documents you can use RTF format. RichTextBox can be also used to edit this kind of documents.

How do you manipulate a MS Word document (.docx) programmatically using vb.net?

I am trying to read from a .docx file (MS Word 2013) using vb.net and find and replace multiple words within the same document. I do not want to make use of a plugin or add-on within vb.net but rather program this myself.
Which libraries or references within vb.net will give me the ability manipulate MS Word documents with the .docx file extension.
Any related vb.net code for Visual Studio 2013 would be greatly appreciated.
I have found the following related information (https://support.microsoft.com/en-us/kb/316383) although I am finding difficulty in adapting it for Visual Studio 2013.
Below is a list of COM references directly from Visual Studio 2013 and the only similar option with reference to the above link seems to be the checked item in the screen print below:
Seems that after a bit of "connecting the dots" from everyone's commentary (thank you) I was missing an imports reference that works with the "Microsoft Word 14.0 Object Library" associated with MS Word 2013.
With reference to https://support.microsoft.com/en-us/kb/316383, the imports reference that I found was adapted from the question: How to load Word Object Library properly in Visual Studio Express i.e. adding the following to the top of the object class solves this question:
Imports Microsoft.Office.Interop
You can use DocX to replace text in one or muliple documents, check the sample code here - Replace text across many documents in Parallel . Hope I am not misunderstanding you.
To run your application you need to have MS Word installed on the PC. I'd consider using the Open XML SDK instead. See Welcome to the Open XML SDK 2.5 for Office for more information.

Fill in PDF Forms from VB.NET application

I am being tasked with creating a Windows application in VB.Net, and one of the requirements is to read data from an MSSQL database, and put in certain values into a PDF form. How can I achieve putting data into a pre-existing PDF file using VB.Net? Also, is it possible to put the PDF file in as a resource instead of calling it externally?
You may be able to take advantage of a 3rd party component like iTextSharp which is a PDF library. It's written in C#, but could be added to your existing solution as a separate project, or compiled and referenced as a library.
This library specifically references the ability to fill in PDF forms and should fit the bill for filling in your pre-existing PDF form programatically.
Docotic.Pdf library can be used for filling PDF forms.
There are samples for the library (C# and VB.NET versions available) that show how to:
Fill existing form
Find control by name
And you might find Write data from a database to PDF blog entry useful in your case, too.
Disclaimer: I am one of the developers of the library.

Tools to manipulate doc file and convert them to pdf

I am looking for some good tools (free or paid, though free tool is always preferred)
for doing following operations on word doc files:
Manipulation of doc/docx/text files (like replacing some placeholders with DB values) as well as
converts doc files to .pdf
Because, I will be using this tool in my WCF service library,
So I am looking for a code library and not for a GUI based product.
Please share your experience regarding same.
Thank you!
Aspose has a decent collection of MS Office and PDF manipulation libraries.
Aspose Homepage
On the off chance that you're only looking for PDFs for viewing or archival purposes, you could also setup a PDF print driver and print your office files into a given location using Automation. You could also edit Office files through Automation although this may be tedious.
VSTO would give you access to the save as PDF from the Office applications.
Please see my answer to a related question on SO where I recommend a number of ways to convert your Word document to a format that is more easy to manipulate programmatically (using XSL-FO).