使用Office interops的.Net Print PowerPoint文档

时间:2015-04-15 05:45:45

标签: .net printing powerpoint

我正在开发一个小项目,可以使用一些打印机选项打印office文档。

MS Word互操作与docs这个词很好用,但是当我尝试使用powerpoint interop类似的东西时,它不起作用。

我的代码用于打印Word文档,使用缩放在一张纸上打印4页。

public void test5()
    {
        try
        {
            // Declaring the object variables we will need later
            object varFileName = filePath;
            object varFalseValue = false;
            object varTrueValue = true;
            object varMissing = Type.Missing;

            Microsoft.Office.Interop.Word.Application varWord =
                new Microsoft.Office.Interop.Word.Application();

            Microsoft.Office.Interop.PowerPoint.Application varPPT = new Microsoft.Office.Interop.PowerPoint.Application();

            Microsoft.Office.Interop.Word.Document varDoc =
           varWord.Documents.Open(ref varFileName, ref varMissing,
              true,
              ref varMissing, ref varMissing, ref varMissing, ref varMissing,
              ref varMissing, ref varMissing, ref varMissing,
              ref varMissing, ref varMissing, ref varMissing, ref varMissing,
              ref varMissing, ref varMissing);

            varDoc.Activate();
            varDoc.PrintOut(PrintZoomColumn: 2, PrintZoomRow: 2);

           }
        catch (Exception varE)
        { 
            MessageBox.Show("Error:\n" + varE.Message, "Error message");
        }
    }

非常简单。我需要做的是在PrintOut方法上添加PrintZoomColumn,PrintZoomRow选项。但是,根据MSDN,PowerPoint缺乏这样的选择。 PrintZoomColunm和PrintZoomRow都不存在。但是,我在Presentation类下找到了一个名为PrintOptions的方法,但这并未显示任何效果。

这是我打印PPT文件的代码。

public void test6()
    {
        try
        {
            // Declaring the object variables we will need later
            object varFileName = filePath;
            object varFalseValue = false;
            object varTrueValue = true;
            object varMissing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.Application varPPT = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentation varPre = varPPT.Presentations.Open(filePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            varPre.PrintOptions.HandoutOrder =Microsoft.Office.Interop.PowerPoint.PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst;
            varPre.PrintOut();
        }
        catch (Exception varE)
        {
            MessageBox.Show("Error:\n" + varE.Message, "Error message");
        }
    } 

在上面的代码中,更改printoptions的handoutorder值不会显示任何效果。我应该在一个页面上打印多张幻灯片?

1 个答案:

答案 0 :(得分:2)

我认为您还需要设置OutputType属性。 HandoutOrder告诉powerpoint如何在页面上布置幻灯片如果在一个页面中有多个幻灯片

presentation.PrintOptions.OutputType = Microsoft.Office.Interop.PowerPoint.PpPrintOutputType.ppPrintOutputFourSlideHandouts;

每页应该给你4张幻灯片