title: Hide all extra excel columns with Apache-POI
body: <p>This is my aim:</p>
  
  <p><a href="https://i.stack.imgur.com/kJNMg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kJNMg.png" alt="excel screenshot with extra columns hidden"></a></p>
  
  <p>I am generating an xlsx file using Apache POI. I would like to hide all the unused columns to the right of the columns I am using. In Excel, this is a relatively simple operation: I can select all the extraneous columns and tell them all to hide in one action. In Apache POI, the only option I seem to have is <a href="https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFSheet.html#setColumnHidden%28int,%20boolean%29" rel="nofollow noreferrer"><code>sheet.setColumnHidden(index, true)</code></a>. If I try to do this for every extraneous column:</p>
  
  <pre><code>for (int i = myLastColumn+1; i &lt; 16384; ++i) {
      sheet.setColumnHidden(i, true);
  }
  </code></pre>
  
  <p>then the library tries to create over 16 thousand columns in order to hide them, which is impractical: it gets slower and slower as it goes, and never finishes. There doesn't seem to be a <code>setColumnRangeHidden</code> or anything like that.</p>
  
  <p>Is there a way to hide nearly all the columns in Apache POI?</p>