Fit all columns on one page when printing the excel sheet

I am currently using aspose.cells.dll (v7.3.1.0) , and I want to print out one excel sheet with several columns. The problem is I want to print all of them within one sheet. I noticed that in excel 2010, there is a print opinion called “Fit All Columns on One Page”, but I didn’t find it in my dll version. Is there a way to archive that?

Hi Jimmy,

Thanks for your posting and using Aspose.Cells.

You can fit all columns in a single page while printing your Excel workbook into PDF. This feature is not available in the previous version (i.e v7.3.1.0), you will have to download and use the latest version: Aspose.Cells for .NET (Latest Version) .

Please see the following documentation article that explains this feature for your reference.


Thanks for the reply. Is there any way that we can fit all columns in a single page by printing the excel file directly without PDF way.

Hi,


With latest version/fix, I think you may try the following sample code, please refer to it for your needs:
e.g
Sample code:

//Instantiate a workbook.
//Open an Excel file.
Workbook workbook = new Workbook(“e:\test\Book1.xls”);
//Define a worksheet.
Worksheet worksheet;
//Get the second sheet.
worksheet = workbook.Worksheets[1];
//Apply different Image / Print options.
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
options.PrintingPage = PrintingPageType.Default;
options.AllColumnsInOnePagePerSheet = true;
SheetRender sr = new SheetRender(worksheet, options);

//Print the sheet.
sr.ToPrinter(strPrinterName);


Thank you.

Thanks for the reply. But my license cannot use the dll you gave, is there any other lower version or free trial version? Or I only need to use the msi format file?

Hi,

Thanks for using Aspose.Cells.

AllColumnsInOnePagePerSheet feature was introduced in the Aspose.Cells 7.7.0 , so you will have to use the Aspose.Cells 7.7.0 or greater. You cannot use the older version than this version.

Please see the following blog post for your reference.

C# Excel to PDF – Fit All Worksheet Columns onto Single PDF Page

so where I can get the v7.70 dll?

Hi,

Thanks for using Aspose.Cells.

You can get the latest version from the following download links.

Aspose.Cells for .NET (Latest Version)

Do we have the option in the page setup class to specify Fit all columns on one page. I have attached the excel print options as your refer.

Hi Jimmy,

Thanks for using Aspose.Cells.

Please use the following code to set the Excel print option - Fit All Columns on One Page.

I have attached the output xlsx file and screenshot highlighting the applied option on the output xlsx file for your reference.

C#


Workbook workbook = new Workbook();


Worksheet worksheet = workbook.Worksheets[0];

worksheet.PageSetup.FitToPagesWide = 1;

worksheet.PageSetup.FitToPagesTall = 0;


workbook.Save(“output.xlsx”);

thanks for the update. One more question, if we have too many rows in the excel sheet, will the print result to be more than 1 page or still within one page?

Hi,


Well, using the code segment i.e…,
e.g
Sample code:

worksheet.PageSetup.FitToPagesWide = 1;

worksheet.PageSetup.FitToPagesTall = 0;



will try to print all the columns on one page but it does not care about rows as the rows might render on multiple pages accordingly. If you do need to fit all rows on the single page (if possible), you may also try to use: “FitToPagesTall = 1” as well for your needs.

Thank you.