How to check a column is hidden or not in excel file using apache poi

点点圈 提交于 2019-12-22 08:54:18

问题


I am trying to parse a xls file using apache poi. Is it possible to check whether a column is hidden or not. How can I get the width of a particular column.

Example: According to the post here it checks if the row is hidden or not.

Similarly I want to check the width of a column ( or check if the column is hidden or not)


回答1:


you can set a column as hidden/unhidden by using

 sheet.setColumnHidden(int columnIndex, boolean hidden); 

e.g.

 sheet.setColumnHidden(2, true);   // this will hide the column index 2
 sheet.setColumnHidden(2, false);   // this will unhide the column index 2

and the column is hidden or not can be checked using

  sheet.isColumnHidden(int columnIndex);

e.g.

  sheet.isColumnHidden(2);   //this will check the 2nd column index whether it is hidden or not



回答2:


The Sheet class has the method boolean isColumnHidden(int columnIndex) and also the method int getColumnWidth(int columnIndex), however the returned width is a unit of character width. Not sure if that helps you.



来源:https://stackoverflow.com/questions/17676049/how-to-check-a-column-is-hidden-or-not-in-excel-file-using-apache-poi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!