使用altchunk元素合并文档后返回OpenXmlUnknownElement [英] After merge of documents using altchunk element returned as OpenXmlUnknownElement

查看:150
本文介绍了使用altchunk元素合并文档后返回OpenXmlUnknownElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,

我们正在使用altchunks将文档附加到父文档中的内容控件中。使用以下代码:

We are appending documents using altchunks into a content control in a parent document. Using the below code:

---------------

---------------

string chunkId = String.Format(" ; AltChunkId {0}"," myChunk" + j)的;

AlternativeFormatImportPart块= mainDocPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML,块ID);

string chunkId = String.Format("AltChunkId{0}", "myChunk" + j);
AlternativeFormatImportPart chunk = mainDocPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, chunkId);

块.FeedData(compFileMS);
$
AltChunk altChunk = new AltChunk();

altChunk.Id = chunkId;

chunk.FeedData(compFileMS);
AltChunk altChunk = new AltChunk();
altChunk.Id = chunkId;

//删除内容控制现有文本

if(myBlock.GetFirstChild< SdtContentBlock>()!= null)

{   

//remove content control existing text
if (myBlock.GetFirstChild<SdtContentBlock>() != null)
{   

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; myBlock.GetFirstChild< SdtContentBlock>()InnerXml = NULL;

      myBlock.GetFirstChild<SdtContentBlock>().InnerXml = null;



}


}

myBlock.AppendChild(altChunk) ; $
  j ++;

myBlock.AppendChild(altChunk);
 j++;

-----------

-----------

合并后,使用生产力工具,我们看到节点作为OpenXmlUnknownElements而不是SdtProperties,SdtContentBlock返回。 有没有理由发生这种情况?如何使用altchunk返回正确定义的SdtBlock
子元素?

After the merge, using the productivity tool we see that the nodes are returnd as OpenXmlUnknownElements instead of SdtProperties, SdtContentBlock.  Is there a reason why this is occurring? How can altchunk be used to return the correctly defined SdtBlock child elements?

我感谢任何帮助。

推荐答案

Hi CoolShaw,

Hi CoolShaw,

我测试了你的代码,它确实作为OpenXmlUnknownElements返回。根据我的分析,无法在SdtBlock元素下插入altChunk。如果是 在SdtBlock元素下插入,它将被重新识别为
OpenXmlUnknownElements。 openxml  sdk可能会被指定为。

请尝试以下代码段:

I tested your code and it is indeed returned as OpenXmlUnknownElements. Based on my analysis, the altChunk can't be inserted under the SdtBlock elment. If it is  inserted under the SdtBlock element, it will be recongnized as OpenXmlUnknownElements . The openxml sdk might be designated as such.
Please try the following code snippet:

            SdtBlock sdtblock = mainPart.Document.Descendants<SdtBlock>().First();
            if (sdtblock.GetFirstChild<SdtContentBlock>() != null)
            {
                sdtblock.GetFirstChild<SdtContentBlock>().InnerXml = null;
            }
            //sdtblock.Append(altChunk);
            mainPart.Document.Body.Append(altChunk);

代码插入&NBSP;&NBSP; altChunk直接&NBSP;身下,那么它是不被认为是
OpenXmlUnknownElements。

希望这可以解释这个场景,并且在你尝试之后随时可以跟进。

The code insert  altChunk directly under the body, then it is not considered as the OpenXmlUnknownElements .
Hope this can explain the scenario and just feel free to follow up after you have tried.

最诚挚的问候,


这篇关于使用altchunk元素合并文档后返回OpenXmlUnknownElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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