我正在尝试在MS word文档的customXMLParts中插入一些文本。有很多使用C#或VBA的示例,但我找不到任何使用C++接口的示例用法。
因此,通常在VBA中您只需执行以下操作:
ActiveDocument.CustomXMLParts.Add "<dataOrigin>abcdef</dataOrigin>"但是,如果我想使用MSO14中的C++接口做同样的事情。“Add”函数接口略有不同:
_CustomXMLParts : _IMsoDispObj
{
...
virtual HRESULT __stdcall Add (
/*[in]*/ BSTR XML,
/*[in]*/ VARIANT SchemaCollection,
/*[out,retval]*/ struct _CustomXMLPart * * ppPart ) = 0;
}所以我的问题是这个SchemaCollection应该是什么?存在_CustomXMLSchemaCollection类型,但它似乎与VARIANT类型不兼容。或者我应该只传递xml模式的stringfy版本?
我试着用下面的方法调用函数,但它似乎不起作用,只是出错了:
// ... some initial code to get customXMLParts
BSTR xmlContent = SysAllocString(L"<dataOrigin>abcdef</dataOrigin>");
const char * xmlSchema = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
"<xs:element name=\"dataOrigin\" type=\"string\"></xs:element>"
"</xs:schema>";
Office14::_CustomXMLPart * outXML (nullptr);
customXMLParts->Add(xmlContent, xmlSchema, &outXML);大多数的例子我谷歌似乎是为C#或VBA,谁知道schemaCollection应该是什么,或有一个例子如何正确调用CustomXMLParts.Add使用c++接口?
发布于 2019-07-21 01:02:45
实际上,我想通了。它只是customXMLParts自己的模式集合。
BSTR xmlContent = SysAllocString(L"<dataOrigin>abcdef</dataOrigin>");
Office14:_CustomXMLSchemaCollection * schemaCollection ( nullptr );
customXMLParts->get_SchemaCollection( &schemaCollection );
Office14::_CustomXMLPart * outXMLPart (nullptr);
customXMLParts->Add( xmlContent, _variant_t(schemaCollection), &outXMLPart);https://stackoverflow.com/questions/57086112
复制相似问题