如何使用 Apache POI 3.6 在 Excel 表中获取超过 255 列 [英] How to get more than 255 columns in an excel sheet using Apache POI 3.6

查看:44
本文介绍了如何使用 Apache POI 3.6 在 Excel 表中获取超过 255 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Excel 中创建日历.第 1 列是 01.01.2010 (dd.MM.yyyy),第 2 列是 02.01.2010,依此类推.

I'm creating a calendar in excel. Column 1 is 01.01.2010 (dd.MM.yyyy), Column 2 is 02.01.2010 and so on.

这是我的代码:

int day_cell = 0;

for(int i = 0; i < days.size(); i++)
{
     Date day = days.get(i);

     HSSFCell cell = row.createCell(day_cell++);
     cell.setCellValue(day.toString());
}

当我到达第 256 列时,POI 抛出此异常:

When I get to column 256 POI throws this exception:

java.lang.IllegalArgumentException: Invalid column index (256).  Allowable column range for BIFF8 is (0..255) or ('A'..'IV')
at org.apache.poi.hssf.usermodel.HSSFCell.checkBounds(HSSFCell.java:926)
at org.apache.poi.hssf.usermodel.HSSFCell.<init>(HSSFCell.java:162)
at org.apache.poi.hssf.usermodel.HSSFRow.createCell(HSSFRow.java:141)
at org.apache.poi.hssf.usermodel.HSSFRow.createCell(HSSFRow.java:119)

我发现这个错误报告表明它已在 3.6 版本中修复.我们使用的是 3.5,但更改为 3.6 似乎没有任何好处.有人有任何提示吗?

I found this bug-report suggesting it was fixed in the 3.6 release. We were using 3.5 but changing to 3.6 doesn't seem to do any good. Anyone got any tips?

https://issues.apache.org/bugzilla/show_bug.cgi?id=46806

似乎错误问题与公式有关..

Seems like the bug-issue was about formulas..

推荐答案

我想通了.我不得不从 org.apache.poi.hssf.usermodel 切换到 org.apache.poi.ss.usermodel

I figured it out. I had to switch from the org.apache.poi.hssf.usermodel to the org.apache.poi.ss.usermodel

这允许您使用 16k 列或类似的东西.

This allows you to use 16k columns or something like that.

这篇关于如何使用 Apache POI 3.6 在 Excel 表中获取超过 255 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆