簡體   English   中英

使用C#的PowerPoint打印問題

[英]power point printing problem using C#

我正在使用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();
        }
    }
}

我只需要設置

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

這樣就可以完成工作。

我不能告訴你,但我敢打賭,你可以很容易地發現自己...

我假設這是一個與桌面交互的應用程序,而不是某些后台服務。

我將緩慢地遍歷代碼,看看它是否有效。(對於app.visible = true和否)。如果有效,則可能是ppoint打印功能和ppoint關閉文檔/退出之間的競爭。 (即使您已經關閉了后台打印),您也需要檢查...

祝好運

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM