Answered by:
How to Read section and content of section in Word Add-in

Question
-
Hi,
I am trying to create a word Add-in for Word 2010. The word document being opened is in a specific format and has specific sections defined in it. I am looking for a way to read all the major sections and their content inside my word Add-in ? I have got to the point where I read XML data using Active document's property "ActiveDocument.Content.WordOpenXML" but there is all kind of styling information attached in it.
Since I am already working inside Word I am not hoping to do parsing of this XML using WordOpenXML. Is there any other way I can read these sections and it's content directly ?
Thanks,
Keyrav
C#Tuesday, October 5, 2010 3:05 PM
Answers
-
Hello Keyrav,
Thanks for posting. I'd suggest you could use the object in Word to access the content. Assume that there are some tables in document. We could access each table using Document.Tables collection. With regard to the kind of object, it depends on the contents in the document. There may be pictures, tables, and bookmarks. We probably could get a relative object exposed by Word Object Model. You could get started here.
Actually, WordOpenXML property will return an XML string that contains of the document in the Word Open XML format. About the issue concerning OpenXML file formats, the best place would be OpenXML forum and OpenXMLDeveloper.org. Based on my limited knowledge about Open XML, Open XML SDK may be helpful. However, I am not sure about this point.
- OpenXMLDeveloper.org
- OpenXML SDK forum: http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/threads/.
If you have any concern on this post, just feel free to follow up. Have a nice day.
Best regards,
Bessie Zhao - MSFT
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Bessie Zhao Tuesday, October 12, 2010 10:10 AM
Wednesday, October 6, 2010 2:59 AM -
To add to what Bessie has said, manipulating the WordOpenXML string - even using something like XPath - is just making work for yourself. When you're in Word, the Word Object Model is the tool to use.You don't give detail of the specific format, or whether you are using the term 'section' to mean a Word Document Section, or more loosely just to mean a part of a document. Assuming the former, ActiveDocument.Sections(1).Range.Text, for example, will give you the textual contents of Section 1.
Enjoy,
Tony
www.WordArticles.com- Marked as answer by Bessie Zhao Tuesday, October 12, 2010 10:10 AM
Wednesday, October 6, 2010 9:24 AM
All replies
-
Hello Keyrav,
Thanks for posting. I'd suggest you could use the object in Word to access the content. Assume that there are some tables in document. We could access each table using Document.Tables collection. With regard to the kind of object, it depends on the contents in the document. There may be pictures, tables, and bookmarks. We probably could get a relative object exposed by Word Object Model. You could get started here.
Actually, WordOpenXML property will return an XML string that contains of the document in the Word Open XML format. About the issue concerning OpenXML file formats, the best place would be OpenXML forum and OpenXMLDeveloper.org. Based on my limited knowledge about Open XML, Open XML SDK may be helpful. However, I am not sure about this point.
- OpenXMLDeveloper.org
- OpenXML SDK forum: http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/threads/.
If you have any concern on this post, just feel free to follow up. Have a nice day.
Best regards,
Bessie Zhao - MSFT
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Bessie Zhao Tuesday, October 12, 2010 10:10 AM
Wednesday, October 6, 2010 2:59 AM -
To add to what Bessie has said, manipulating the WordOpenXML string - even using something like XPath - is just making work for yourself. When you're in Word, the Word Object Model is the tool to use.You don't give detail of the specific format, or whether you are using the term 'section' to mean a Word Document Section, or more loosely just to mean a part of a document. Assuming the former, ActiveDocument.Sections(1).Range.Text, for example, will give you the textual contents of Section 1.
Enjoy,
Tony
www.WordArticles.com- Marked as answer by Bessie Zhao Tuesday, October 12, 2010 10:10 AM
Wednesday, October 6, 2010 9:24 AM -
Hello again Keyrav,
I am writing to check the status of this thread on your side. If you have any concern on this issue, just feel free to follow up, or unmark it back. Have a nice day.
Best regards,
Bessie Zhao - MSFT
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Tuesday, October 12, 2010 10:08 AM