I am using NPOI Version 2.5.3 in my C# application and am trying to set the scaling option (Fit All Columns on 1 Page). Which seems easy enough to do from these questions here and here.
The problem:
So, my problem occurs when using the code below. All that does is configures; both the width and height to fit to one page. I assumed it was because of the sheet.FitToPage = true.
private void SetPrintSettings(XSSFSheet sheet)
{
sheet.SetMargin(MarginType.BottomMargin, 0.5);
sheet.SetMargin(MarginType.TopMargin, 0.5);
sheet.SetMargin(MarginType.LeftMargin, 0.45);
sheet.SetMargin(MarginType.RightMargin, 0.45);
sheet.SetMargin(MarginType.HeaderMargin, 0.3);
sheet.SetMargin(MarginType.FooterMargin, 0.3);
sheet.Autobreaks = true; //auto breaks
sheet.FitToPage = true; //THIS SETS IT TO ALL FIT ON ONE PAGE
var PrintSetup = sheet.PrintSetup;
PrintSetup.FitWidth = 1; //fit width onto 1 page
PrintSetup.FitHeight = 0; //don't care about height
PrintSetup.Landscape = true;
PrintSetup.PaperSize = 3; //paper size 11x17
}
When doing the code above I get the following output in Excel.
So after that did not work I tried setting it to false like shown below.
private void SetPrintSettings(XSSFSheet sheet)
{
sheet.SetMargin(MarginType.BottomMargin, 0.5);
sheet.SetMargin(MarginType.TopMargin, 0.5);
sheet.SetMargin(MarginType.LeftMargin, 0.45);
sheet.SetMargin(MarginType.RightMargin, 0.45);
sheet.SetMargin(MarginType.HeaderMargin, 0.3);
sheet.SetMargin(MarginType.FooterMargin, 0.3);
sheet.Autobreaks = true; //auto breaks
sheet.FitToPage = false;
var PrintSetup = sheet.PrintSetup;
PrintSetup.FitWidth = 1; //fit width onto 1 page
PrintSetup.FitHeight = 0; //don't care about height
PrintSetup.Landscape = true;
PrintSetup.PaperSize = 3; //paper size 11x17
}
When change the configuration, it renders "No Scaling" as shown below.
No matter what I try I can't seem to get this to work. I've tried a variety of settings and nothing seems to work. I am beginning to think its a bug with the version I am using. It doesn't help that almost all the examples I find are for Java POI so I am unsure if it is just an approach issue.
Desired Output:
Below is what I am trying to do. Just set the scaling option to Fit columns onto 1 page. If anyone could help me out or point me in the right direction that would be fantastic.