2009-07-22 61 views
3

我目前正在嘗試使用C#和OpenOffice做一個mailmerge。Mailmerge使用OpenOffice

我在我的數據庫中有一個destanatary的列表。我想這是可能的:

  • 用戶編輯面向對象的文檔,把 領域,如「名」,「住址」,「城市」 和一些標準文本(例如:「你好 名稱如何你呢?」,
  • 編輯風格,等等等等,
  • 然後去我的應用程序,集團公司在 ‘發送到數據庫中的所有用戶。’

然後程序遍歷所有用戶,並且爲每個用戶使用DB數據替換OO文檔中的mailmerge字段,通過郵件/打印/其他方式發送。

問題:我找不到任何方式,在C#中,用DB數據替換OO文檔中的mailmerge字段,因爲我無法找到屬性/方法處理這些字段。

請幫助我的年度獎金取決於它! (原文如此)

我發現的唯一指針是看起來我需要UNO庫,但它似乎並不存在於C#中。

回答

4

使用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/

希望這有助於

+0

感謝您的回答,但什麼是使用後「在哪裏」的代碼?有關C#/ OpenOffice的文檔非常少:/ – 2009-07-23 06:20:32