【问题标题】:power point printing problem using C#使用 C# 的 power point 打印问题
【发布时间】:2009-07-16 01:14:23
【问题描述】:

我正在使用 Office 2007 中的 COM 对象来处理和打印 ms-office 文件。我对 word 和 excel 文档没有任何问题,但我无法打印 Power Point 文档。

下面的代码只是打开文件,向打印机发送作业,但没有打印出来

我做错了什么? =(

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Main
{
    class PrintPPoint
    {
        public static void PrintPPointDocument(string filename, int copies, string range)
        {
            Microsoft.Office.Interop.PowerPoint.Presentation work = null;            
            Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
            Microsoft.Office.Interop.PowerPoint.Presentations presprint = app.Presentations;
            //app.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
            work = presprint.Open(filename, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
            work.PrintOptions.PrintInBackground = 0;
            work.PrintOptions.ActivePrinter = app.ActivePrinter;
            if (range.Equals("0"))            
            {                
                work.PrintOut(0, 1, app.ActivePrinter, copies, Microsoft.Office.Core.MsoTriState.msoFalse);                
            }
            else
            {
                string[] toprintsheet = range.Split(new char[] { ',' });
                foreach (string aux in toprintsheet)
                {
                    work.PrintOptions.PrintInBackground = 0;
                    work.PrintOptions.ActivePrinter = app.ActivePrinter;
                    if (aux.Contains("-"))
                    {
                        int from = 0, to = 0;
                        string[] SplitRange = aux.Split(new char[] { '-' });
                        from = Convert.ToInt16(SplitRange[0]);
                        to = Convert.ToInt16(SplitRange[1]);                        
                        work.PrintOut(from, to, app.ActivePrinter, 1, Microsoft.Office.Core.MsoTriState.msoFalse);
                    }
                    else
                    {
                        work.PrintOut(Convert.ToInt16(aux), Convert.ToInt16(aux), app.ActivePrinter, copies, Microsoft.Office.Core.MsoTriState.msoFalse);
                    }

                }
            }
            work.Close();
            app.Quit();
        }
    }
}

【问题讨论】:

    标签: c# printing powerpoint


    【解决方案1】:

    我只需要设置

    PrintOptions.PrintInBackground = Microsoft.Office.Core.MsoTriState.msoFalse
    

    这可以让作业完成。

    【讨论】:

      【解决方案2】:

      我不能告诉你,但我敢打赌你可以很容易地找到自己......

      我假设这是一个与桌面交互的应用程序,而不是一些后台服务。

      我会慢慢浏览代码,看看它是否有效。(对于 app.visible = true 和 not。)如果有效,则可能是点打印功能和点关闭文档/退出之间的竞争。 (即使您已关闭后台打印)并且您已检查...

      祝你好运

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-23
        • 1970-01-01
        • 2014-02-23
        相关资源
        最近更新 更多