简体   繁体   English

使用C#的PowerPoint打印问题

[英]power point printing problem using C#

I'm using the COM objects from Office 2007 to handle and print ms-office files. 我正在使用Office 2007中的COM对象来处理和打印ms-office文件。 I don't have any problems with word and excel documents, but i just can't print Power Point docs. 我对word和excel文档没有任何问题,但是我无法打印Power Point文档。

the code bellow just opens the file send a job to the printer but nothing gets printed 下面的代码只是打开文件,将作业发送到打印机,但没有打印任何内容

what am i doing wrong? 我究竟做错了什么? =( =(

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();
        }
    }
}

I just needed to set 我只需要设置

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

That lets the jobs complete. 这样就可以完成工作。

I can't tell you but I bet you can easily find out yourself... 我不能告诉你,但我敢打赌,你可以很容易地发现自己...

I assume that this is an application that interacts with the desktop and not some background service. 我假设这是一个与桌面交互的应用程序,而不是某些后台服务。

I would step through the code slowly and see if it works.. (for both app.visible = true and not.) If it works, it may be a race between ppoint printing functionality and ppoint closing the document/quiting. 我将缓慢地遍历代码,看看它是否有效。(对于app.visible = true和否)。如果有效,则可能是ppoint打印功能和ppoint关闭文档/退出之间的竞争。 (Even though you've turned off background printing) and you have check for that... (即使您已经关闭了后台打印),您也需要检查...

Good luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM