title: NPOI C# set columns to fit on one page
body: <p>I am using NPOI Version 2.5.3 in my C# application and am trying to set the scaling option (<strong>Fit All Columns on 1 Page</strong>). Which seems easy enough to do from these questions <a href="https://stackoverflow.com/questions/36432953/how-can-it-set-the-file-for-fit-all-columns-on-one-page-setting">here</a> and <a href="https://mail-archives.apache.org/mod_mbox/poi-user/201308.mbox/%3C1375955582.58916.YahooMailNeo@web122301.mail.ne1.yahoo.com%3E" rel="nofollow noreferrer">here</a>.</p>
  <p><strong>The problem:</strong></p>
  <p>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 <strong>sheet.FitToPage = true</strong>.</p>
  <pre><code>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
  }
  </code></pre>
  <p>When doing the code above I get the following output in Excel.</p>
  <p><a href="https://i.stack.imgur.com/TMLCU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TMLCU.png" alt="enter image description here" /></a></p>
  <p>So after that did not work I tried setting it to false like shown below.</p>
  <pre><code> 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
  }
  </code></pre>
  <p>When change the configuration, it renders &quot;No Scaling&quot; as shown below.</p>
  <p><a href="https://i.stack.imgur.com/hWxnT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hWxnT.png" alt="enter image description here" /></a></p>
  <p>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.</p>
  <p><strong>Desired Output:</strong></p>
  <p>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.</p>
  <p><a href="https://i.stack.imgur.com/pHtUb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pHtUb.png" alt="enter image description here" /></a></p>