转载:解决poi导出excel中文列宽问题

使用列宽自适应方法

sheet.AutoSizeColumn(i);  

只能解决英文、数字列宽自适应,如果该列为中文,会出现列宽不足现象。

可通过手动设置列宽解决

首先通过value.getBytes().length方法,对比找到该列数据最大长度。

通过sheet.setColumnWidth(i,cellLength*2*256);手动设置列宽。

长度乘以2是为了解决纯数字列宽度不足会显示科学计数法问题,乘以256得到的数据才是excel真实列宽。

原文:http://blog.csdn.net/soundfly/article/details/7398108

注:poi 自动调整列宽语句

     sheet.autoSizeColumn((short)i);
     sheet.autoSizeColumn((short)i,true);

 

posted @ 2014-08-11 16:42  菜枚  阅读(1168)  评论(0)    收藏  举报