tags:

views:

245

answers:

2

Edit: I have a user control with embedded excel sheet and gridviews ( WinForm). I have a form which has that user control. I have a print button on top and I want to convert the whole form into printable format. Any suggestion on how to move ahead?

A: 

Printing an Excel document can be done using the Workbook.ExportAsFixedFormat method:

ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF 
    FileName:=“sales.pdf” 
    Quality:=xlQualityStandard 
    DisplayFileAfterPublish:=True

This method should be preferred over using SaveAs because it also allows specifying all PDF / XPS options.

Note: This method has been added to the Excel object model with Excel 2007 and requires the Save as PDF or XPS Add-in for 2007 Microsoft Office programs to be installed.

See this related question: What is the FileType number for PDF in Excel 2007 that is needed to save a file as PDF through the API?

0xA3
I want to print the excel worksheet and two other gridviews that are there in the user control all in a single click of button.
A: 

For versions earlier than 2007 you can embed/install a PDF printer and use the PrintOut method, specifying ActivePrinter as required.

Lunatik