Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a XML file generated in run time on my program.This XMLfile.InnerText() is having some formats(Like -enter,spaces,tab,Alignments) as below,

This a test of the windows driver

2115 -XXXXXXXXXX BRANCHXXXX
XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XX XXXXXXXXXX : 08/23/16
XXX XXX: 08/23/16
XXXXXXXX XXXXXX : 9
------------------------------------------------------------------

XXXXXX XXX X XXXX:
XXX 0,01
XXXXXX XXX XXXXX:
1 XXXXXXXXX
------------------------------------------------------------------

I am trying create a word document with this XMLfile.InnerText(with this above format& alignments) using VB.net(provided the used code as example).
By using Microsoft.Office.Interop.Word.Application -> Range.InsertXML() method i am able to bring this same format in the word file.
But How to capture the same XML format in my newly created word file by using OpenXML method?

What I have tried:

Dim vWordDoc As WordprocessingDocument = WordprocessingDocument.Create(tmppath, WordprocessingDocumentType.Document)

                    ' Set the content of the document so that Word can open it.
                    Dim vMainPart As MainDocumentPart = vWordDoc.AddMainDocumentPart()

                    ' Create the document structure and add some text.
                    vMainPart.Document = New Document()

                    Dim vBody As Body = vMainPart.Document.AppendChild(New Body())
                    Dim vPara As Paragraph = vBody.AppendChild(New Paragraph())
                    Dim run As Run = vPara.AppendChild(New Run())
                    run.AppendChild(New Text(XMLFile.InnerText))
                    vMainPart.Document.Save()
                    vWordDoc.Close()
Posted
Updated 11-Mar-19 6:23am
v3
Comments
[no name] 11-Mar-19 10:20am    
You have a "working solution", but you want to use OpenXML instead but don't know how? Brilliant.
Member 14146557 11-Mar-19 10:31am    
As per my project requirement i should use OpenXML only. But i am not familiar with this openxml method. That's the reason....

1 solution

 
Share this answer
 
Comments
Member 14146557 12-Mar-19 5:29am    
Thanks for your information.. I have read these articles but i cant find any solution for my requirement in these items.
Richard MacCutchan 12-Mar-19 5:38am    
Sometimes you need to study the documentation and actually work out the answer for yourself. There is no guarantee that you will find an example that answers your specific requirement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900