This project is read-only.

Error in 1.2.4 but not 1.2.3: calculated end index (<some#>) is out of allowable range (<some#>..<someother#>)

Dec 9, 2011 at 8:36 PM

In POI users are seeing this in 3.7 but not 3.6.

 In NPOI, I'm seeing this in 1.2.4 but not 1.2.3.

I am opening a file, making a workbook, iterating through all sheets, all rows, and all cells. If a cell is not null I check cell.CellStyle.WrapText == true - if so, I'm setting it false.

When HSSFWorkbook.write(), I get "calculated end index (<somenumber>) is out of allowable range (<somenumber>..<someothernumber>)" when saving workbooks with many sheets.

 No exception thrown in 1.2.3 version of NPOI.dll for .Net 2.0 when writing a file containing one, or many, sheets.

Exception thrown in 1.2.4 version of NPOI.dll for .Net 2.0 when writing a file containing many sheets ... (ok with 1 sheet).

Have you seen this?


Tom Holden




Dec 12, 2011 at 2:52 PM

The numbers that you reference (<somenumber>) may be important.  What are those number?

It looks like the error is getting thrown by the LittleEndianByteArrayOutputStream constructor because it thinks the byte array/file size is less than 0 or because the end point of the file exceeds the interpreted byte length of the stream/file.  Without debugging through their code, it's tough to know anything else.


Dec 12, 2011 at 4:31 PM


I didn't save the numbers. The first number in the error message was larger than the other two. So the end point of the file probably exceeded the interpreted byte length of the stream/file - just like you said.

If they'd like, the team can reproduce by attempting to write a workbook to .xls, having multiple sheets containing data.  I open a workbook having multiple sheets containing data, I iterate through all sheets, rows, and cells. If a cell has wrapping turned on, I turn it off. Then I call write().  1.2.4 does not work but 1.2.3 does work.

For the implementation I'm doing, I won't be able to use 1.2.4.  I've implemented the previous stable release and changed code to work with it.

Thanks for responding.


Dec 12, 2011 at 4:58 PM

I've got NPOI source on my machine.  I'd be happy to debug into it to see where the problem is stemming.

I have a wrapper you can check out too.  It's been pretty successful for me in my implementations.  The wrapper is at

You could do something like the following:

ExcelWrapper excel= new ExcelWrapper("c:\\file.xls");            

for(int s = 0; s < excel.WorksheetCount; s++)

   for(int r = 0; r <= excel.GetNumberOfRows(); r++)
      for(int c = 0; c <= excel.GetNumberOfColumns(); c++)
          ExcelStyle style = new ExcelStyle();
          string currentValue = excel.GetCellValue(r, c);

          style.WrapText = currentValue.Length > 0;

          excel.WriteCellValue(r, c, currentValue, style);

Dec 12, 2011 at 6:18 PM

Tim - nice wrapper!  I will use it if I do other tasks with Excel files.

My software allows outside products to call a web service in my app, which streams invoices to Excel, on-demand, from a report server. NPOI is the final step. I am using it to apply final sheet settings and modify cell formatting - certain things that cannot be easily set in the report definition.

If you do get a chance to debug that .write(), let me know. If the fix gets applied to a future version of NPOI, I'll implement that right away.

I estimated my task for 4-8 hours, start-to-finish, but it took 25 start-to-finish.  It's possible, but not probable, for me to circle back around in my personal spare time...  maybe in a week or two after I recover from the experience. 

But, the software is in use and humming along for a good purpose now.  I appreciate your helping out on NPOI. From what I can tell, it looks like a good product.  It seems a bug got introduced into POI 3.7 and NPOI 1.2.4, but I don't know.