简体   繁体   中英

How can I determine paragraph and line indents in MS Word documents with c#?

Any one Please tell me is there any way to determine indents of each line and paragraph in MS word documents. I'm new in Office programming and I intend to write an application which convert documents to text while they keeps their styles with converting intents to white-spaces.

Take a look to WordML, it's a XML file which contains a doc document. It's quite easy to generate and edit one. :)

http://msdn.microsoft.com/en-us/library/aa212812%28v=office.11%29.aspx

http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats

The xml in .docx files is complicated but you can ignore most of it (especially if reading it via the C# library). Unzip the docx and look in word/document.xml. The indent is specified in the paragraph properties (w:pPr). eg this is the xml for a paragraph indented by 540 somethings (about one tab's width, not sure what the units are):

<w:p w:rsidR="009932EC" w:rsidRDefault="009932EC" w:rsidP="000A0336">
  <w:pPr>
    <w:ind w:left="540" />
  </w:pPr>
  <w:r>
    <w:t>Indented.</w:t>
  </w:r>
</w:p>

Documentation is here:

http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.indentation.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM