.Net 使用 Office 互操作打印 PowerPoint 文档

.Net Print PowerPoint Document using Office interops

我正在做一个小项目,它可以使用一些打印机选项打印办公室文档。

MS Word interop 与 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 class 下找到了一个名为 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 值没有显示任何效果。在一页上打印多张幻灯片需要什么?

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

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

每页应该给你 4 张幻灯片