We have an ASP.NET/SQL Server web application that needs to have a massive “mail merge” functionality. We have implemented the free Open XML SDK solution for our users; however, the users have already built 100+ Microsoft Word templates and we are running into issues because each template seems to be different. What does Aspose.Words provide that would solve our issue? Do you have an example of bringing one-to-many database tables into MS Word? Thanks.
I would like to correct my above statement. It really isn’t a mail merge. The application needs to produce one document with a lot of DOCVariables in it. Does anyone have any examples of the best way to do this using Aspose.Words? Thx
Hi Marvin,
for your inquiry.
First of all please note that Aspose.Words for .NET
is a class library that enables your applications to perform a great
range of document processing tasks. Aspose.Words supports DOC, DOCX,
RTF, HTML, OpenDocument, PDF, XPS, EPUB and other formats. With
Aspose.Words you can generate, modify, convert, render and print
documents without utilizing Microsoft Word®. For more information,
please go through the documentation below:
http://www.aspose.com/docs/display/wordsnet/Introducing+Aspose.Words+for+.NET
- Please attach your input Word documents.
- Please
attach your target Word document showing the desired behavior. You can
use Microsoft Word to create your target Word document. I will
investigate as to how you are expecting your final document be generated
like.
us, we will then provide you more information about your query along with code.
I have attached my input template Word document and my target Word document showing the desited behavior. The paragraphs highlighted are those that have a DocVariable inside of it to be replaced by data from our SQL Server.
Hi Marvin,
for sharing the documents.
A field in a Word document is a complex structure
consisting of multiple nodes that include field start, field code, field
separator, field result and field end. Fields can be nested, contain
rich content and span multiple paragraphs or sections in a document. The
Field class is a “facade” object that provides properties and methods
that allow to work with a field as a single object.
content between the field start and separator is the field code. The
content between the field separator and field end is the field result.
The field code typically consists of one or more Run objects that
specify instructions. The processing application is expected to execute
the field code to calculate the field result.
var doc = new Aspose.Words.Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection collection = doc.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart start in collection)
{
if (start.FieldType == FieldType.FieldDocVariable)
{
builder.MoveTo(start);
builder.Writeln("Your contents...");
}
}
foreach (FieldStart start in collection)
{
if (start.FieldType == FieldType.FieldDocVariable)
{
start.GetField().Remove();
}
}
doc.Save(MyDir + "Out.docx");