poi的autoSizeColumn方法对全角或者说中文支持不好的一个解决办法

来源:互联网 发布:excel多个表格数据求和 编辑:程序博客网 时间:2024/04/28 05:12

http://blog.csdn.net/aotian16/article/details/6270912

就是自动对齐后,获取列宽,

如果小于预期,就重新设置宽度

 

一小段代码

  1. /* 自动调整宽度 */  
  2. for (int i = 0; i < 6; i++) {  
  3.     sheet.autoSizeColumn(i);  
  4. }  
  5. /* 实际宽度 */  
  6. int curColWidth = 0;  
  7.   
  8. /* 默认宽度 */  
  9. int[] defaultColWidth = { 200020002000300030002000 };  
  10. /* 实际宽度 < 默认宽度的时候、设置为默认宽度 */  
  11. for (int i = 0; i < 6; i++) {  
  12.     curColWidth = sheet.getColumnWidth(i);  
  13.     if (curColWidth < defaultColWidth[i]) {  
  14.         sheet.setColumnWidth(i, defaultColWidth[i]);  
  15.     }  
  16. }  

     

    原创粉丝点击