vb.net - Merging Documents with Open XML -
i looking mail merge alternatives in vb.net app. have used mail merge feature of word, , find quite buggy when dealing large volume of documents. looking @ alternate methods of generating merge, , have come across open xml. think answer looking for. have come understand merge entirely code-driven in vb.net. have started playing around following code:
dim wordprocessingdocument wordprocessingdocument = wordprocessingdocument.open("c:\users\jasonb\documents\test.docx", true) 'for each simplefield (mergefield) each field in wordprocessingdocument.maindocumentpart.document.body.descendants(of simplefield)() 'get document instruction values dim instruction string() = field.instruction.value.split(splitchar, stringsplitoptions.removeemptyentries) 'if mergefield if instruction(0).tolower.equals("mergefield") dim fieldname string = instruction(1) each fieldtext in field.descendants(of text)() fieldtext.text = "i testing" next end if wordprocessingdocument.maindocumentpart.document.save() wordprocessingdocument.dispose()
now works great , all, realizing need create many documents have datarows (assuming use datatable handle data).
one suggestion found loop through each datarow, take document template, save folder , insert datarow data. mean end 12,000 documents in single folder need joined later , converted pdf.
is there option? other thing stood out me create new word document, , duplicate on xml template, , replace values. dont know if there "simpler" way of doing this, thanks.
if don't want save 12,000 documents file should able process, convert , email them 1 @ time using temporary files.
converting docx pdf in .net might issue looks it's possible using word automation (saving word docx files pdf).
the bottom line don't need generate documents before emailing them if perform process 1 document @ time. can use smtpclient
in vb.net email pdf after generated.
in terms of creating document have seen reports generated simple string replace used replace string such '%firstname%' person's name , on. isn't best approach can work quite well. way can create template in word or openoffice , edit in .net using openxml.
Comments
Post a Comment