We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PrintArea to PDF

I’m trying to create a small test program that:

1. Opens a large XLSM file
2. Access a specific worksheet
3. Sets a Print Area (quite small)
4. Prints the contents in the Print area to a PDF file.

It runs but dumps tons of data into the PDF file.

Any ideas? See attached.


Thanks for your posting and using Aspose.Cells.

Please check the sample769.xlsm and MyBook_area.pdf files. We tested this issue with your sample code using the recent version (links given below) but we are unable to find any problem.

Please also note, if your worksheet is quite large but you are only printing a part of it, then it will not help you in terms of memory and performance because all data of worksheet needs to be loaded before it could be rendered to Pdf.

If you still find any issue, then either modify the sample769.xlsm in MS-Excel or provide your own xlsm file for our testing. We will look into it and help you asap.

Latest Version Links:
Aspose.Cells for .NET v17.4.6 (.NET 2.0) compiled in .NET Framework 2.0.
Aspose.Cells for .NET v17.4.6 (.NET 4.0) compiled in .NET Framework 4.0.

In the sample769.xlsm, try adding a worksheet before and after the Cover Letter worksheet. Doesn’t matter what’s in each worksheet. Then run it. I get data from all three worksheet and not just from the letter worksheet where I have a print area set.

I’ve upgraded to the latest version.


Thanks for your posting and using Aspose.Cells.

If you do not want to render your other worksheets, then you should hide them. Please check this sample Excel file and the following sample code and its comments. Please also check the output pdf generated by the code for your reference. As you can see in the output pdf that it only shows the contents of your target worksheet (as per your print area) and hide the contents of all other worksheets.

//Load your source Excel file.
Workbook wb = new Workbook(dirPath + “sample769.xlsm”);

//Access your worksheet
Worksheet ws = wb.Worksheets[“Cover Letter - CPA”];

//Set its print area
PageSetup pageSetup = ws.PageSetup;
pageSetup.PrintArea = “C5:H12”;

//Hide all other worksheets because we don’t need them in pdf
int cnt = wb.Worksheets.Count;

for(int i=0; i<cnt; i++)
Worksheet sh = wb.Worksheets[i];

sh.IsVisible = false;

//Save the workbook into pdf
PdfSaveOptions opts = new PdfSaveOptions();
opts.OnePagePerSheet = true;

wb.Save(“output.pdf”, opts);

Thanks for the sample code! It’s working great!

Even running with a massive spreadsheet it still runs extremely fast.