使用C#與OpenOffice的一般幫助:
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 here。請參閱OpenOffice.org Developer's guide。
UPDATE。 一個更加有用的鏈接:
http://blog.nkadesign.com/2008/net-working-with-openoffice-3/
希望這有助於
感謝您的回答,但什麼是使用後「在哪裏」的代碼?有關C#/ OpenOffice的文檔非常少:/ – 2009-07-23 06:20:32