VSTO词-为什么有时会缺少paraId [英] Word VSTO - Why paraId is sometimes missing

查看:223
本文介绍了VSTO词-为什么有时会缺少paraId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从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...

添加了代码示例

在某些文档中为"0",在某些文档中为有效的十六进制ID

This is in some documents "0" and in some documents a valid hex id

string sParaId = range.Paragraphs.First.ParaID.ToString("x").ToUpper();

此打开的xml文档有时具有有效的w14:paraId属性,有时会丢失:

This open xml document sometimes have valid w14:paraId-attribute and sometimes it is missing:

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";

推荐答案

在以下情况下返回或设置指定对象的标识标签: 当前文档将另存为网页.

Returns or sets the identifying label for the specified object when the current document is saved as a Web page.

由于未将文档另存为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:

保留供内部使用.

Reserved for internal use.

不确定您真正要执行的操作是什么,但是可以使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆