I have a template excel file with few sheets of data and macro. I run the macro in excel application and the macro is creating a new empty sheet to the workbook, then the POI is running and is writing data to the latter empty sheet in the template file. After POI was running when trying to open the workbook in excel application (excel 2000 - 9.0.3821 SR-1) I got an application error - "The instruction at "0x3005c5eb" referenced memory at "0x0000018". The memory could not be written", afterwards I have to manually kill the excel process. I overcome the problem in a weard way , If , after the macro was running , I manually delete the empty sheet and create it again and then run POI then every thing is o.k. It seems that the creation of empty sheet via macro is affecting POI later on. Any Ideas ?
we need a sheet + easy-to-run program to replicate this. Excel throws this for nearly ANY problem with the xls. (great piece of software eh ;-))
I'm in the middle of a development project using POI as an Excel report generator, so I don't have a simple example separated out from my code. However, I was able to reproduce this bug by taking a existing spreadsheet file with 5 worksheets on it 15 rows x 25 col per (file size = 2M). In my code I created an additional worksheet and wrote debug information to the new sheet, row by row. For each row I would create a number of new cells, using a 'cell counter' to identify where in the row I wanted the new cell to appear. Instead of resetting my 'cell counter' value each time I created a new row I just kept incrementing it, and the resulting spreadsheet would not open. When I modified my code to reset the 'cell counter' the spreadsheet would open fine. The resulting 'cell counter' value in the spreadsheets that would not open was 966. So the bug seems to be related to either a maximum allowable cell number per row or a maximum number of empty cells per row. If there is interest I can try to extract out an example.
It seems the error occured only when I import new macro code to the template (so I know the reason its not so bad), then some old objects exist and the error occured , again I overcome it by deleting and creating the sheet each time I import new macro code to my template.
William, yes, it will be great if you could extract an example. As Andy explained, excel throws this kind of an error for *any* sheet corruption issue (it could be one misplaced byte out of millions!), so without an example sheet, its quite impossible to figure out what is happening.
4 years later, POI generally behaves a lot better. It's likely that whatever caused this specific bug has been fixed. This is not to say that POI will never write a file that will crash Excel. In the event that a similar bug re-surfaces, some sample code (or the offending file at least) will be required to diagnose the issue.