My current project use EPPlus to create Excel files. These files are printed by the user and I'm trying to force the Excel file to print in only one A4 page, regardless the width og the content.
Actually, when the file is printed, it takes two pages and the second contains just one column.
My code:
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.PrintArea = ws.Cells[ws_dimension_adress];
ws.PrinterSettings.TopMargin= 0;
ws.PrinterSettings.RightMargin = 0;
ws.PrinterSettings.BottomMargin = 0;
ws.PrinterSettings.LeftMargin = 0;
ws.Cells[ws_dimension_adress].AutoFitColumns();
ws.Cells[ws_dimension_adress].Style.Font.Size = 9;
The result: The result provided by my code
What I need:
I searched things like "autofit to A4 page", eso but no solution yet.
Remark: all the columns are needed. I can't simply delete one before creating the file.
Thanks for helping!
I found the solution.
EPPlus has a printerSettings for this. The line to use is
ws.PrinterSettings.FitToPage = true;
By using this, the default files properties force Excel to print the data in only one page.
Hope this help some other devs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With