开发者

Export to Excel from Java - InvocationTargetException

开发者 https://www.devze.com 2023-01-24 07:44 出处:网络
I am stuck at a point while trying to export some data into Excel. Here is my code List<String> headers = new ArrayList<String>();

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 t开发者_开发百科o 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)


InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor.

Could be, that the exception is thrown while creating a HSSFRichTextString class. In this case, I'd look (debug) at the value of headers.get(i) first.

There is a good chance, that you actually have a nested IndexOutOfBoundsException, because the size of the headersHSSF array may be bigger than the size of the headers list.

Change the loop signature to:

for (int i = 0; i < headers.size(); i++) {

and check, if the error is the same, gone or different.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号