简体   繁体   中英

Print Excel Worksheet/Workbook

I'm trying to improve performance of a C# Winform project.

Previously, generate an Excel file was during 100000ms (using Office.Interop.Excel). Using ClosedXml it is about 5000ms. Really Great. But now I need to print this Excel document (only a Worksheet or the entire workbook)

I was doing this before (using office interop) :

public void PrintCurrentWorksheet()
{
    this._activeWorksheet.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
public void PrintWorkbook()
{
    this._activeWorbook.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}

But now type of _activeWorkbook and _activeWorksheet are XLWorkbook and IXLWorksheet . So there is no Printout method. I could not find a print method and I suppose there is not because OpenXml is not relied to Excel. Am I right?

I could not find a Shell command to print a Worksheet.

So, is there a simple way to print a Workbook/Worksheet without using Interop?

Libraries that allow you to read and write Excel-compatible files are, like most libraries, " headless ".

The code in them can be used to write data in a format that Excel (and compatible applications) understand, but they generally do not offer a (link to a) user interface, nor a way to render the contents of the Excel file to another file format or a printer. Because that is outside the scope of the library. Reading and writing files is one thing, rendering their contents properly is a whole other thing.

There are libraries that do support printing Excel files, such as Aspose .

You can always only use interop to print , while generating the document using libraries. Or you can send the "print" verb to Excel , which will print using default settings to the default printer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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