2

In c# i am generating an excel in specific format, i have to print the same excel format on click_print.

P.s.-Microsoft Office not available,using SpreadSheetGear for this.

Dark Knight
  • 125
  • 2
  • 10
  • GetExcel() - Downloads excel in given format,Now i have to write a new function PrintExcel() on click event,I am not able to figure out any way or any function to do so.To elaborate more,for eg: we have sheet.Printout() method if use Microsoft Office,then how it will be done for SpreadsheetGear – Dark Knight Sep 11 '14 at 15:16

2 Answers2

2

I recommend Chuck's answer if you have a UI and are utilizing the WorkbookView control. If you are generating this workbook in-code without a UI, you can also print a workbook by using the WorkbookPrintDocument class. Below is an example that demonstrates this in a console application:

using SpreadsheetGear;
using SpreadsheetGear.Printing;
using SpreadsheetGear.Drawing.Printing;

static void Main(string[] args)
{
    // Create a workbook with some cell data
    IWorkbook workbook = Factory.GetWorkbook();
    IWorksheet worksheet = workbook.ActiveWorksheet;
    IRange cells = worksheet.Cells;
    cells["A1:D10"].Value = "=RAND()";

    // Create a WorkbookPrintDocument.  
    WorkbookPrintDocument printDocument = new WorkbookPrintDocument(worksheet, PrintWhat.Sheet);

    // Set the printer if necessary...let's go old school.
    printDocument.PrinterSettings.PrinterName = "Epson MX-80";

    // Print it
    printDocument.Print();
}

If you are using the .NET 4.0 build of SpreadsheetGear 2012, you'll need to add a reference to the SpreadsheetGear2012.Drawing.dll assembly to access the SpreadsheetGear.Drawing.Printing namespace.

Also note that I specify to print (the used range of) the sheet via PrintWhat.Sheet. See the SpreadsheetGear.Printing.PrintWhat enum for more options.

Lance Fisher
  • 25,684
  • 22
  • 96
  • 122
Tim Andersen
  • 3,014
  • 1
  • 15
  • 11
1

Spreadsheetgear has a print method for the objects they provide.

http://www.spreadsheetgear.com/support/help/spreadsheetgear.net.3.0/SpreadsheetGear~SpreadsheetGear.Windows.Forms.WorkbookView~Print.html

This should get you started.

Chuck Buford
  • 321
  • 1
  • 9