在 OpenOffice 中使用 C# 的一般帮助:
http://www.oooforum.org/forum/viewtopic.phtml?p=151606
http://opendocument4all.com/content/view/68/47/
对于 OO 3.0,您需要引用 cli_*.dll 库,它们在安装 OO 时被放入 GAC。
初始化 OO 连接的示例代码:
private static XMultiServiceFactory _multiServiceFactory;
private static XComponentLoader _componentLoader;
private static XFileIdentifierConverter _urlConverter;
private static void Initialize()
{
XComponentContext localContext = uno.util.Bootstrap.bootstrap();
_multiServiceFactory = (XMultiServiceFactory)localContext.getServiceManager();
_componentLoader = (XComponentLoader)_multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
_urlConverter = (XFileIdentifierConverter)_multiServiceFactory.createInstance("com.sun.star.ucb.FileContentProvider");
}
加载文档:
string url = _urlConverter.getFileURLFromSystemPath(Path.GetPathRoot(path), path);
XComponent xComponent = _componentLoader.loadComponentFromURL(url, "_blank", 0, new PropertyValue[] { MakePropertyValue("Hidden", new uno.Any(true))});
XTextDocument doc = (XTextDocument)xComponent;
在哪里
private static PropertyValue MakePropertyValue(string cName, Any uValue)
{
PropertyValue oPropertyValue = new PropertyValue();
if (!string.IsNullOrEmpty(cName))
oPropertyValue.Name = cName;
oPropertyValue.Value = uValue;
return oPropertyValue;
}
在此处阅读有关 XTextDocument的更多信息。
另请参阅OpenOffice.org 开发人员指南。
更新。另一个有用的链接:http:
//blog.nkadesign.com/2008/net-working-with-openoffice-3/
希望这可以帮助