Generate xls from xls template - null exception on get row

Mar 29, 2011 at 4:46 PM

I'm using an existing xls template to generate a new XLS file. The row are dynamically inserted based on how many records there are from the dataset. However, I'm running into problem on this line:

sheet.GetRow(2).GetCell(1).SetCellValue("test");

This always throw the null exception, perhaps because it couldn't find Row #2? But I can't tell how many rows there will be ahead of time. I thought we don't have to create row, based on the example, it says that "//create cell on rows, since rows do already exist,it's not necessary to create rows again.".

Any suggestions?

Thank you.

Coordinator
Apr 1, 2011 at 6:52 PM

There is no cell created at the position (2,1) (equals to B3). You should call CreateCell(1) before calling SetCellValue

Apr 7, 2011 at 5:10 PM

Thanks tonyqus... Got it to work now.