使用C#的power point打印问题 [英] power point printing problem using C#

查看:64
本文介绍了使用C#的power point打印问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the COM objects from Office 2007 to handle and print ms-office files. I don't have any problems with word and excel documents, but i just can't print Power Point docs.

下面的代码只是打开文件向打印机发送作业但没有打印任何内容

the code bellow just opens the file send a job to the printer but nothing gets printed

我做错了什么?=(

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

这样才能完成工作.

这篇关于使用C#的power point打印问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆