Hi,
if you are working with VB.NET DOCX file format, you might also check this C# / VB.NET Word library that works without MS Word installed and has its own .NET Word mail merge functionality, so you can merge DataTable directly without a need to export it to CSV first:
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
Dim dataTable = New DataTable("People")
dataTable.Columns.Add(New DataColumn("Name", GetType(String)))
dataTable.Columns.Add(New DataColumn("Surname", GetType(String)))
dataTable.Rows.Add("John", "Doe")
dataTable.Rows.Add("Fred", "Nurk")
dataTable.Rows.Add("Hans", "Meier")
dataTable.Rows.Add("Ivan", "Horvat")
Dim document = New DocumentModel()
document.Sections.Add(
New Section(document,
New Table(document,
New TableRow(document,
New TableCell(document,
New Paragraph(document, "Name")),
New TableCell(document,
New Paragraph(document, "Surname"))),
New TableRow(document,
New TableCell(document,
New Paragraph(document,
New Field(document, FieldType.MergeField, "RangeStart:People"),
New Field(document, FieldType.MergeField, "Name"))),
New TableCell(document,
New Paragraph(document,
New Field(document, FieldType.MergeField, "Surname"),
New Field(document, FieldType.MergeField, "RangeEnd:People")))))))
document.Save("TemplateDocument.docx", SaveOptions.DocxDefault)
document = DocumentModel.Load("TemplateDocument.docx", LoadOptions.DocxDefault)
document.MailMerge.ExecuteRange(dataTable)
document.Save("Document.docx", SaveOptions.DocxDefault)
|