是这样的,我现在拿到一份启用了“限制编辑”模式的文档,可以看到文档中包含有很多“可编辑域”
但是,我希望能将所有这些“可编辑域” 都替换成为 “文本域(内容控件)”
我尝试使用以下代码,试图在第1个可编辑域中插入内容控件(然后再把可编辑域删掉,从而达到我替换的目的…), 但是在尝试添加内容控件的时候会抛出这样的异常信息:
System.ArgumentException:“Cannot insert a node of this type at this location.”
是这样的,我现在拿到一份启用了“限制编辑”模式的文档,可以看到文档中包含有很多“可编辑域”
但是,我希望能将所有这些“可编辑域” 都替换成为 “文本域(内容控件)”
我尝试使用以下代码,试图在第1个可编辑域中插入内容控件(然后再把可编辑域删掉,从而达到我替换的目的…), 但是在尝试添加内容控件的时候会抛出这样的异常信息:
System.ArgumentException:“Cannot insert a node of this type at this location.”
StructuredDocumentTagRangeStart是一个块级节点,您不能将其插入Word文档的“段落”中。 相反,请使用Aspose.Words for .NET API的以下C#代码将Richable Content Content-Controls替换为EditableRange。
Document doc = new Document("C:\\Temp\\229095\\input.docx");
int i = 1;
foreach (EditableRangeStart editableRangeStart in doc.GetChildNodes(NodeType.EditableRangeStart, true))
{
StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Inline);
sdtRichText.Title = "Title_" + i++;
sdtRichText.IsShowingPlaceholderText = false;
sdtRichText.RemoveAllChildren();
ArrayList nodes = new ArrayList();
Node currentNode = editableRangeStart;
while (currentNode != null && currentNode != editableRangeStart.EditableRange.EditableRangeEnd)
{
Node nextNode = currentNode.NextPreOrder(currentNode.Document);
nodes.Add(nextNode);
currentNode = nextNode;
}
foreach (Node node in nodes)
sdtRichText.AppendChild(node);
editableRangeStart.ParentNode.InsertBefore(sdtRichText, editableRangeStart);
}
doc.Save("C:\\temp\\229095\\21.5.docx");
非常感谢,您的代码符合我的诉求
真是不好意思将我自己的工作交由您来完成 …
谢谢