简体   繁体   English

使用Process.Start将Excel文件发送到打印机

[英]Send Excel File to Printer using Process.Start

I want to send excel file to printer with c# console application. 我想使用C#控制台应用程序将Excel文件发送到打印机。 I tried something like this. 我尝试过这样的事情。

    public static void printExcel(string printpath)
    {

        string printerName = String.Empty;
        for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
        {
            string pName = PrinterSettings.InstalledPrinters[i];
            if (pName.Contains("PRINTER"))
            {
                printerName = pName;
                break;
            }
        }

        try
        {
            ProcessStartInfo info = new ProcessStartInfo(printpath); 
            info.Verb = "PrintTo";
            info.Arguments = printerName;
            info.CreateNoWindow = true;
            info.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(info);

        }
        catch (Exception ex) { Console.WriteLine(ex.Message); }

    }

This console application will run like a batch. 该控制台应用程序将像批处理一样运行。 So it must be run without any prompt screen. 因此,它必须在没有任何提示屏幕的情况下运行。 But while app running i got some excel error. 但是,当应用程序运行时,我遇到了一些excel错误。 When i click "yes" excel sent to printer. 当我单击“是”时,Excel发送到打印机。 enter image description here How can i solve this problem? 在此处输入图片描述我该如何解决此问题?

Seems like its about excel's safe mode. 好像是关于excel的安全模式。 if file comes from some other source maybe you should check. 如果文件来自其他来源,也许您应该检查一下。 Can you try to check properties of xlsx file? 您可以尝试检查xlsx文件的属性吗? it maybe blocked and maybe you need to release block. 它可能被阻止,也许您需要释放阻止。

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

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