【问题标题】:Mailmerge using OpenOffice使用 OpenOffice 进行邮件合并
【发布时间】:2009-07-22 15:19:51
【问题描述】:

我目前正在尝试使用 C# 和 OpenOffice 进行邮件合并。

我的数据库中有一个 destanatary 列表。我希望这是可能的:

  • 用户编辑一个 OO 文档,把 “名称”“地址”“城市”等字段 和一些标准文本(例如:“你好 姓名你好吗?",
  • 编辑样式等,
  • 然后转到我的应用程序,点击 “发送给数据库中的所有用户”。

然后程序循环遍历所有用户,并为每个用户将 OO 文档中的 mailmerge 字段替换为 DB 数据,然后通过 mail/print/whatever 发送。

问题:我找不到任何方法,在 C# 中,用 DB 数据替换 OO 文档中的邮件合并字段,因为我找不到处理这些字段的属性/方法。

请帮我拿年终奖就靠它了! (原文如此)

我发现的唯一指针是我似乎需要 UNO 库,但它似乎在 C# 中不存在。

【问题讨论】:

    标签: c# .net openoffice.org mailmerge


    【解决方案1】:

    在 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 here 阅读更多关于你能做什么。

    另见OpenOffice.org Developer's guide

    更新。 另一个有用的链接:
    http://blog.nkadesign.com/2008/net-working-with-openoffice-3/

    希望对你有帮助

    【讨论】:

    • 感谢您的回答,但是“where”后面的代码有什么用?关于 C#/OpenOffice 的文档很少:/
    猜你喜欢
    • 2010-09-07
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多