2012-06-27 4 views
0
wrdMergeFields.Add(wrdSelection.Range, "ProductName") 

위의 코드는 기본적으로 병합 중에 문서의 다른 페이지에있는 모든 productName을 dispose합니다.VB.net을 통한 WordMerge 데이터의 내부

데이터를 테이블에 넣는 방법을 알려주세요. 나는 내 ProductName, AccountNo, OutBalance, AccountName, 등등에 대한 여러 코드를 작성해야한다. 여기서 나의 문제점은 테이블에 넣는 방법을 모른다는 것이다.

+0

어떤 종류 : 여기

은 샘플 VB.NET 코드를 어떻게 (코드에서 템플릿 문서를 만들어 및 파일에서로드하여)을하는 것입니다? 당신의 워드 문서 또는 데이터베이스 테이블에있는 테이블 또는 무엇? –

+0

Word 문서 내부 테이블. 내가 여기서하려고하는 것은 메일 머릿속의 데이터로 테이블을 채우는 것이다. 데이터를 디스패 레이싱 할 수는 있지만 테이블에 셀 단위로 셀을 넣을 수는 없습니다. – user1484788

답변

0

문제를 해결하기 위해 타사 라이브러리에 관심이 있으시면 GemBox.Document 구성 요소를 사용해보십시오. 테이블의

' Use the component in free mode. 
ComponentInfo.SetLicense("FREE-LIMITED-KEY") 

' Define DataTable with two columns: 'Name' and 'Surname', and fill it with some data. 
' You don't have to do this if you already have a DataTable instance. 
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") 

' Create and save a template document. 
' You don't have to do this if you already have a template document. 
' This code is only provided as a reference how template document should look like. 
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) 

' Load a template document. 
document = DocumentModel.Load("TemplateDocument.docx", LoadOptions.DocxDefault) 

' Mail merge template document with DataTable. 
' Important: DataTable.TableName and RangeStart/RangeEnd merge field names must match. 
document.MailMerge.ExecuteRange(dataTable) 

' Save the mail merged document. 
document.Save("Document.docx", SaveOptions.DocxDefault) 

' Open the documents with MS Word. 
Process.Start("TemplateDocument.docx") 
Process.Start("Document.docx")