安装 OpenXML 文件转换器

发布于 2024-09-16 17:37:07 字数 1253 浏览 5 评论 0原文

我已经用 C# 编写了一个托管 OpenXML 文件转换器,但在部署时遇到了问题。对于部署,我使用 VS 安装项目。

我想我的第一个问题是,我看到有些人使用类库,而另一些人则使用 Windows 应用程序作为 COM 服务器。对其中任何一个有偏好吗?我的转换器依赖于不在 GAC 中的库。

当谈到注册COM服务器时,以下帖子: http://blogs.msdn.com/b/speront/archive/2009/04/17/9553717.aspx

建议将其添加到托管 EXE 的 Main() 中:

Application.OleRequired();
MyConverter converter = new MyConverter();
Application.Run();

这对于设置不起作用项目。如果我先手动运行 EXE,这确实有效。

我尝试运行 regasm:

regasm MyConverter.dll,它成功了,但是当 Microsoft Word 尝试使用转换器时,我收到错误“Word 无法启动转换器 MyConverter Document”

,我尝试创建一个 Windows 应用程序并使用:

public static void Main(string[] args)
{
     Guid guid = new Guid("EFADDB5B-933E-49FE-B3C8-F6FD7FB1B788");

     RegistrationServices regSrv = new RegistrationServices();

     regSrv.RegisterTypeForComClients(typeof(MyConverter), ref guid);
}

接下来 ,我尝试过:

regasm /regfile:test.reg MyConverter.dll

然后导入注册表文件。

所有这些都会出现错误:“Word 无法启动转换器 MyConverter Document”

我的转换器在 Office\12.0\Word\Text Converters\OOXML Converters\Import 中有正确的注册表项

转换器已成功工作。只是部署在任何实例下都不起作用。

I have written a managed OpenXML file converter in c#, but I'm having trouble with the deployment. For deployment, I am using a VS Setup Project.

I guess my first question is, I see some people using a Class Library and others using a Windows Application as the COM server. Is there a preference on either one? My converter has dependencies on libraries not in the GAC.

When it comes to registering the COM server, the following post: http://blogs.msdn.com/b/speront/archive/2009/04/17/9553717.aspx

suggests adding this to the Main() of a managed EXE:

Application.OleRequired();
MyConverter converter = new MyConverter();
Application.Run();

Which would not work for a setup project. This does work though if I manually run the EXE first.

I've tried running regasm:

regasm MyConverter.dll, which succeeds, but when Microsoft Word tries to use the converter, I get the error "Word cannot start the converter MyConverter Document"

Next, I tried creating a Windows Application and using:

public static void Main(string[] args)
{
     Guid guid = new Guid("EFADDB5B-933E-49FE-B3C8-F6FD7FB1B788");

     RegistrationServices regSrv = new RegistrationServices();

     regSrv.RegisterTypeForComClients(typeof(MyConverter), ref guid);
}

Lastly, I tried:

regasm /regfile:test.reg MyConverter.dll

and then importing the registry file.

All of these give the error: "Word cannot start the converter MyConverter Document"

I have the correct registry entries for my converter in Office\12.0\Word\Text Converters\OOXML Converters\Import

The converter has successfully worked. It's just that deployment does not work under any instance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲸落 2024-09-23 17:37:07

如果正确设置转换器,则当 Word 尝试启动转换器时,它可能会引发未处理的异常。要弄清楚异常是什么,最好用 try/catch 块包装所有接口方法并记录异常堆栈跟踪:

public void HrImport(
    string bstrSourcePath,
    string bstrDestPath,
    IConverterApplicationPreferences pcap,
    out IConverterPreferences ppcp,
    IConverterUICallback pcuic)
{
    try
    {
        // code to import document
    }
    catch (Exception ex)
    {
        // log the exception
        // 
        System.Diagnostics.Trace(ex.ToString());
    }
}

If you set up the converter correctly it might be that it throws an unhandled exception when Word tries to start it. To figure out what the exception is it is probably a good idea to wrap all of your interface methods with a try/catch block and log the exception stack trace:

public void HrImport(
    string bstrSourcePath,
    string bstrDestPath,
    IConverterApplicationPreferences pcap,
    out IConverterPreferences ppcp,
    IConverterUICallback pcuic)
{
    try
    {
        // code to import document
    }
    catch (Exception ex)
    {
        // log the exception
        // 
        System.Diagnostics.Trace(ex.ToString());
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文