无法使用C#以编程方式打开MS发布者文件 [英] Can't open MS publisher file pro-grammatically using C#

查看:105
本文介绍了无法使用C#以编程方式打开MS发布者文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我们正在用C#(.NET Framework 4.5)开发一个应用程序来打开MS Publisher文件和转换为PDF。



我们在Windows Server 2016中使用Office打开文件时遇到问题(2013 - 确切版本15.0.4869.1000)。



同样的文件在Windows中按预期工作nbsp; 2012 R2  与Office(2013年 - 确切的
版本15.0.4869.1000)。



这是我们用来打开文件的示例代码,



公共MSPublisherDocument打开(字符串文件名,布尔只读,布尔AddToRecentFiles,Microsoft.Office.Interop.Publisher.PbSaveOptions选项)

   &NBSP ; {

      object [] Params = new object []

        ;  {

           filename,

           只读,  //真

           AddToRecentFiles,/ / false

           options

       ;  };
$


         //打开第一个工作表

         MSPublisherDocument It = new MSPublisherDocument(_Application.GetType()。InvokeMember(

                    "打开", 

                    System.Reflection.BindingFlags.InvokeMethod,

                null,b $ b                _Application,

                Params,

                CultureInfo.InvariantCulture));

               退货;

        }





这是样本,



https://drive.google.com/open?id=1g-ynEkpg33Ic95ky6hLbvjX0RU1TgC-2



如果你能的话会很棒帮助我们找出实际原因。



谢谢。

解决方案

Hello AvinashMR,


什么是MSPublisherDocument?我检查了Publisher对象模型,但没有找到这样的对象。


对于打开MS Publisher文件并转换为PDF,我们通常会尝试使用Publisher Interop dll。尝试参考下面的代码。

使用Publisher = Microsoft.Office.Interop.Publisher; 


Publisher.Application application =新Publisher.Application();
application.ActiveWindow.Visible = TRUE;
串路径= @" C:\Users\terryx\Downloads\Test_File.pub英寸;
Publisher.Document文档= application.Open(路径,FALSE,TRUE,Publisher.PbSaveOptions.pbPromptToSaveChanges);
document.ExportAsFixedFormat(Publisher.PbFixedFormatType.pbFixedFormatTypePDF,@" C:\Users\terryx\\ \\Desktop\ExportedPDF.pdf&q uot;);
document.Save();
document.Close();
application.Quit();

最好的问候,


Terry



Hi,

We are developing an application in C# (.NET Framework 4.5) to open MS Publisher File and convert into PDF.

We are having an issue while opening a file in Windows Server 2016 with Office (2013 - exact version 15.0.4869.1000 ).

Same file works as expected in Windows 2012 R2 with Office (2013 - exact version 15.0.4869.1000).

Here is the sample code we are using for opening a file,

public MSPublisherDocument Open(string filename, bool ReadOnly, bool AddToRecentFiles, Microsoft.Office.Interop.Publisher.PbSaveOptions options)
        {
         object[] Params = new object[]
                {
                    filename,
                    ReadOnly,  //true
                    AddToRecentFiles, //false
                    options
                };

                //Open the first work sheet
                MSPublisherDocument It = new MSPublisherDocument(_Application.GetType().InvokeMember(
                    "Open", 
                    System.Reflection.BindingFlags.InvokeMethod,
                null,
                _Application,
                Params,
                CultureInfo.InvariantCulture));
                return It;
        }

Here is the sample,

https://drive.google.com/open?id=1g-ynEkpg33Ic95ky6hLbvjX0RU1TgC-2

It would be great if you can help us to figure out the actual cause.

Thanks.

解决方案

Hello AvinashMR,

What is MSPublisherDocument ? I checked Publisher Object Model and did not find such an Object.

For opening MS Publisher File and convert into PDF, we usually try to use Publisher Interop dll. Please try to refer to below code.

using Publisher=Microsoft.Office.Interop.Publisher;


            Publisher.Application application = new Publisher.Application();
            application.ActiveWindow.Visible = true;
            string path = @"C:\Users\terryx\Downloads\Test_File.pub";
            Publisher.Document document = application.Open(path, false, true, Publisher.PbSaveOptions.pbPromptToSaveChanges);
            document.ExportAsFixedFormat(Publisher.PbFixedFormatType.pbFixedFormatTypePDF, @"C:\Users\terryx\Desktop\ExportedPDF.pdf");
            document.Save();
            document.Close();
            application.Quit();

Best Regards,

Terry


这篇关于无法使用C#以编程方式打开MS发布者文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆