POI导出excel单元格内容过大报错

在用POI导出excel时报错

java.lang.IllegalArgumentException: The maximum column width for an individual cell is 255 characters.

原因:导出excel时,excel表中的某个单元格数据过大,在创建时,使用了localHSSFSheet.setColumnWidth()控制住了单元格的列宽,所以会显示单元格最大列宽255错误。

解决办法:

1、将这段语句注释掉即可,单元格显示不美观。

2、将列宽设置大点

for (int i = 0; i < headerList.size(); i++) {  
            int colWidth = sheet.getColumnWidth(i)*2;
            if(colWidth<255*256){
                sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);    
            }else{
                sheet.setColumnWidth(i,6000 );
            }
        }

3 评论

  1. A formidable share, I just given this onto a colleague who was doing somewhat analysis on this. And he in truth bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the deal with! However yeah Thnkx for spending the time to debate this, I feel strongly about it and love reading more on this topic. If attainable, as you develop into expertise, would you mind updating your blog with extra details? It is highly useful for me. Large thumb up for this weblog publish! Jorge Boscarello

  2. Very good point which I had quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Holisticly restore superior interfaces before flexible technology. Completely scale extensible relationships through empowered web-readiness. Whitney Soard

  3. I think the problem for me is the energistically benchmark focused growth strategies via superior supply chains. Compellingly reintermediate mission-critical potentialities whereas cross functional scenarios. Phosfluorescently re-engineer distributed processes without standardized supply chains. Quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Noel Yafei

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注