问题描述
我正在从openXML中检索段落样式名称,并使用paraID属性来获取正确的样式名称.
I'm retrieving paragraph stylenames from openXML and using paraID property to get the right one.
在测试过程中,我注意到,取决于单词文档,该属性可能不会出现在任何段落中.
During testing i noticed that depending on the word document the attribute might not be present on any of the paragraphs.
我确实知道这是Word的内部运行时段落ID.
I do know that this is a internal runtime paragraph id for Word.
所以问题是:是什么在段落上生成paraId属性,似乎无法弄清楚.
ps.我不想使用get_style(),因为那太麻烦了...
ps. I don't want to use get_style() since that is waay too slooooow...
添加了代码示例
string sParaId = range.Paragraphs.First.ParaID.ToString("x").ToUpper();
activeDocument = Globals.ThisAddIn.Application.ActiveDocument;
wordXML = XElement.Parse(activeDocument.WordOpenXML);
...我想从WordOpenXML中获得类似的styleName,但现在看来我可能会选择其他选项,因为我不知道何时在XML中添加paraId.
... I would like to get the styleName something like this from the WordOpenXML but for now it seems i might go for some other option since I don't know when paraId is added in the XML.
paraEl = ooXMLElementList.Descendants().Where(x => x.Name.LocalName ==
"p").FirstOrDefault(x => x.Attribute(w14 + "paraId")?.Value == sParaId);
styleName = paraEl.Descendants().FirstOrDefault(x => x.Name.LocalName ==
"pStyle") != null ? paraEl.Descendants().FirstOrDefault(x =>
x.Name.LocalName == "pStyle").Attribute(w + "val").Value : "Normal";
推荐答案
从 Paragraph.ID :
由于未将文档另存为HTML,因此该属性没有任何意义.
Since the document is not saved as HTML the property has no meaning.
属性不公开给开发人员使用.它在VBA对象模型中不可见,但是由于PIA(主要互操作程序集)的生成方式,.NET开发人员将看到它.从语言参考中:
The ParaId
property is not exposed for developers to use. It's not visible in the VBA object model, but due to the way the PIA (primary interop assemblies) are generated the .NET developer will see it. From the language reference:
不确定您真正要执行的操作是什么,但是可以使用Word的Range.Find功能搜索格式(样式).
Not sure what it is you're really trying to do, but you can use Word's Range.Find capability to search formatting (styles).
这篇关于VSTO词-为什么有时会缺少paraId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!