Excel print settings

I am having an issue. I need to set the print settings on a generated excel doc to “Fit all columns on one page”

The process is… Client does report, exports to excel, downloads to desktop, may decide to print.

The only option I’ve found for this is in the excel print to pdf conversion, which is not helpful to me.

FitToPagesWide = 1 does not work either. It makes the text too small to read.

Hi Cliff,


Thank you for contacting Aspose support.

If you wish to set the Fit All Columns On One Page for printing purposes then you can use the ImageOrPrintOptions.AllColumnsInOnePagePerSheet for your requirement. Please check the following piece of code a try on your end to see if it fits your needs.

C#

Workbook workbook = new Workbook(“sample.xlsx”);
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.AllColumnsInOnePagePerSheet = true;
SheetRender sheetRender = new SheetRender(workbook.Worksheets[0], options);
sheetRender.ToPrinter(“Printer Name”);
WorkbookRender workbookRender = new WorkbookRender(workbook, options);
workbookRender.ToPrinter(“Printer Name”);

My understanding of that code is that is for when someone presses a link on a webpage to print something. I don’t have that option. They need to download the excel file then be able to hit file > print and the print settings by default are set to fit all columns on one page.

Hi Cliff,


Thank you for writing back.

I believe you require to save the print settings in the spreadsheet it self so that when someone prints the spreadsheet, it is printed with Fit All Columns On One Page. You may achieve this by setting the PageSetup.FitToPagesWide to 1 and PageSetup.FitToPagesTall to 0. Please check the following piece of code and attached screenshot for elaboration.

C#

Workbook workbook = new Workbook(“book1.xlsx”);
foreach (Worksheet sheet in workbook.Worksheets)
{
sheet.PageSetup.FitToPagesWide = 1;
sheet.PageSetup.FitToPagesTall = 0;
}
workbook.Save(“output.xlsx”);

Please note, setting the worksheet to Fit All Columns On One Page should be used when there are not to many columns otherwise you may end up with very small printed text as you have narrated in your original post.