如何读取单词文件并获取段落的样式信息并分配给变量 [英] How to read a word file and get the style information of the paragraph and assign to a variable
问题描述
您好,
我有一个word文档,我想获取段落的stlye信息并将其分配给变量。 Stlye信息,如对齐,左缩进,右缩进。如果样式信息不同,我想标记它们。
例如第一段样式信息是alignment = Justified,Left Indentation是0.75cm和right压痕为0.74cm。和第二段 - 对齐是合理的。左压痕为0.80cm,右压痕为0.75cm。然后我需要识别这个并标记第二段
请帮助。非常紧急。
Hello,
I have a word document, i want to get the stlye information of the paragraphs and assign it to a variable. Stlye information like alignment,left indention,right indentation.and I want to tag them if the style information different.
For example the first paragraph style info is alignment= Justified, Left Indentation is 0.75cm and right indentation is 0.74cm. and the second paragraph -alignment is justified. Left indentation is 0.80cm and right is 0.75cm. then i need to identify this and tag the second para
Please help . its very urgent.
推荐答案
您好,
您可以使用OpenXML执行此操作。
http://msdn.microsoft.com/en -us / library / office / bb456488(v = office.15).aspx [ ^ ]
打开文档:
Hello,
You can do this using OpenXML.
http://msdn.microsoft.com/en-us/library/office/bb456488(v=office.15).aspx[^]
to open a document:
using (WordprocessingDocument doc =
WordprocessingDocument.Open(fileName, true))
{
}
获取段落:< br $>
To get the paragraphs:
doc.MainDocumentPart.Document.Body.Elements<Paragraph>()
获取段落属性:
To get a paragraph properties:
ParagraphProperties paragraphProperties = paragraph.Elements<ParagraphProperties>()
其中一个属性是风格ID:
One of the properties is the style Id:
paragraphProperties.ParagraphStyleId
等...
这里是一篇关于类似内容的文章:
http://blogs.msdn.com/b/brian_jones/archive/2009/05/05/retrieving-word-content-based-on-styles.aspx [<一个href =http://blogs.msdn.com/b/brian_jones/archive/2009/05/05/retrieving-word-content-based-on-styles.aspx\"target =_ blanktitle =New Window > ^ ]
Valery。
etc...
Here is an article talking about something similar:
http://blogs.msdn.com/b/brian_jones/archive/2009/05/05/retrieving-word-content-based-on-styles.aspx[^]
Valery.
这篇关于如何读取单词文件并获取段落的样式信息并分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!