![]() |
#4
|
||||
|
||||
![]()
Basically, those lines would replace your entire foreach loop. I'm not a C# programmer, but it seems to me your code could be reduced to:
Code:
Private void btnExportWord_Click_1(Object sender, EventArgs e) { Object oMissing = Missing.Value; Word.Application oWord = New Word.Application(); Word.Document oWordDoc = New Word.Document(); oWord.Visible = false; oWordDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); Object oTemplatePath = @"C:\test\MyXMLTemplate.dotx"; oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing); For (int i = 0; i < treeViewXMLFiles.Nodes[0].Nodes.Count; i++) { oWord.Characters.Last.InsertParagraphAfter; oWord.Characters.Last.InsertAfter treeViewXMLFiles.Nodes[0].Nodes[i].Text; oWord.Characters.Last.InsertParagraphAfter; oWord.Characters.Last.InsertAfter treeViewXMLFiles.Nodes[0].Nodes[i].Nodes[0].Text; oWord.Characters.Last.InsertParagraphAfter; oWord.Characters.Last.InsertAfter treeViewXMLFiles.Nodes[0].Nodes[i].Nodes[1].Text; oWord.Characters.Last.InsertParagraphAfter; oWord.Characters.Last.InsertAfter treeViewXMLFiles.Nodes[0].Nodes[i].Nodes[2].Text; oWord.Characters.Last.InsertParagraphAfter; } Object oSaveAsFile = (Object)@"C:\test\FINISHED_XML_Template.doc"; oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oWordDoc.Close(False, ref oMissing, ref oMissing); oWord.Quit(ref oMissing, ref oMissing, ref oMissing); }
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Export VBA form Data to CSV | rhys.downard | Outlook | 0 | 02-29-2012 07:35 AM |
![]() |
virencm | Project | 4 | 02-08-2012 03:18 PM |
Export data from multiple attachments into a single excel document | Woolstar | Outlook | 0 | 12-07-2011 09:49 AM |
![]() |
Catalin.B | Excel Programming | 2 | 09-08-2011 11:37 PM |
Create a Custome Form and export data to Access | ashleybyrdnc | Office | 0 | 03-05-2010 09:41 AM |