i try since 3 day to use mail merge group function :
il read all i find
https://www.e-iceblue.com/Tutorials/Spi ... -in-C.html
the code :
- Code: Select all
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Reporting
Imports System.IO
Class sommaire
Dim NUMRANG As String
Dim TITRE As String
Dim ARTICLE As String
Sub New(a, b, c)
NUMRANG = a
TITRE = b
ARTICLE = c
End Sub
End Class
Module Module1
Sub Main()
'data
Dim s1 As sommaire = New sommaire("1", "azerty", "article 14")
Dim s2 As sommaire = New sommaire("2", "Qwerty", "article 15")
Dim li As List(Of sommaire) = New List(Of sommaire)
li.Add(s1)
li.Add(s2)
Dim Table As MailMergeDataTable = New MailMergeDataTable("sommaire", li)
Dim doctest As Document = New Document("C:\tmp\groupesommaire.docx")
Dim sect As Section = doctest.Sections(0)
'group start
Dim MergefielddebutGr As MergeField = New MergeField(doctest)
MergefielddebutGr.Type = FieldType.FieldMergeField
MergefielddebutGr.FieldName = "GroupStart:sommaire"
'group end
Dim MergefieldfinGr As MergeField = New MergeField(doctest)
MergefieldfinGr.Type = FieldType.FieldMergeField
MergefieldfinGr.FieldName = "GroupEnd:sommaire"
' add champgroup at begin and end of pargraph content (3 mailmerges)
Dim PardernierNonvide As Paragraph = sect.Paragraphs(0) 'just for init
Dim _unefois As Boolean = True
For Each par As Paragraph In sect.Paragraphs
'delete empty line
If String.IsNullOrEmpty(par.Text.Trim()) Then
sect.Paragraphs.Remove(par)
Else
If _unefois Then
'add group before pargraph content
par.Items.Insert(0, MergefielddebutGr)
_unefois = False
'record last pargraph with text
PardernierNonvide = par
End If
End If
Next
PardernierNonvide.Items.Add(MergefieldfinGr)
doctest.SaveToFile("C:\tmp\mergegroup.docx", FileFormat.Auto)
doctest.MailMerge.ExecuteGroup(Table)
doctest.SaveToFile("C:\tmp\mergegroupafter.docx", FileFormat.Auto)
End Sub
End Module
the result file before merge look like good but i never merge corectly the data on it .
(before write on forum i try create a new doc with all fields , create group field with word , executegroupe never give a good result)
can you help me .
escuse my poor english
thank's
FH
ps i attached the file to modify and fill.