从 Java 导出到 Excel - InitationTargetException
我在尝试将一些数据导出到 Excel 时陷入困境。
这是我的代码
List<String> headers = new ArrayList<String>();
//////////////////////////////////////////////
/// Added some headers in between to the list
///////////////////////////////////////////////
HSSFCell[] cell = new HSSFCell[headers.size()];
for (int i = 0; i < headersHSSF.length; i++) {
cell[i] = excelRow.createCell(i);
cell[i].setCellValue(new HSSFRichTextString(headers.get(i)));
}
此代码为行抛出 InvokingTargetException
cell[i].setCellValue(new HSSFRichTextString(headers.get(i)));
任何人都可以告诉我发生这种情况的原因吗?
(PS:我是从 Flex UI 调用代码。这不是从 java 代码调用的)
I am stuck at a point while trying to export some data into Excel.
Here is my code
List<String> headers = new ArrayList<String>();
//////////////////////////////////////////////
/// Added some headers in between to the list
///////////////////////////////////////////////
HSSFCell[] cell = new HSSFCell[headers.size()];
for (int i = 0; i < headersHSSF.length; i++) {
cell[i] = excelRow.createCell(i);
cell[i].setCellValue(new HSSFRichTextString(headers.get(i)));
}
This code is throwing InvocationTargetException for line
cell[i].setCellValue(new HSSFRichTextString(headers.get(i)));
Can anyone please tell me the reason why is this happening?
(PS: I am calling the code from Flex UI. This is not called from java code)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是在创建
HSSFRichTextString
类时引发异常。在这种情况下,我会首先查看(调试)headers.get(i)
的值。您实际上很有可能有一个嵌套的
IndexOutOfBoundsException
,因为headersHSSF
数组的大小可能大于headers
的大小> 列表。将循环签名更改为:
并检查错误是否相同、消失或不同。
Could be, that the exception is thrown while creating a
HSSFRichTextString
class. In this case, I'd look (debug) at the value ofheaders.get(i)
first.There is a good chance, that you actually have a nested
IndexOutOfBoundsException
, because the size of theheadersHSSF
array may be bigger than the size of theheaders
list.Change the loop signature to:
and check, if the error is the same, gone or different.