Can anybody help me as how to append in excel sheet using Java. I am able to write i existing excel sheet using HSSF but is not able to append. So please suggest something regarding the sameappendexcel sheet
What exactly do you mean by "append in excel sheet"? You can use the HSSFWorkbook.createSheet methods to append new sheets to an Excel document. If that's not what you're looking for then please describe in more detail what you're trying to do.
Stacktraces are only useful if you include all the code, or if you ensure that line numbers match up. I put your code between BB [code] and [/code] tags in the hope that it would make it more readable, however since line numbers don't match up and your indentation was not good, it didn't really help.
Anyway - you should consider using JDK 5 generics and the new for loop - it will make the issues far more obvious. For example, if I change your initialization of the data to be added like so:
And I then change the method signature of writeExcel to also use generics:
Then change the loop over the collection:
Now, thanks to generics, the compiler immediately highlights your error: You are trying to cast lValue to a StringBuffer, when you originally only put Strings into your collection. Hence the error java.lang.ClassCastException: java.lang.String
Since you don't use lSqlLine in your code anywhere you could remove that line without any problems.
That will probably result in a brand new runtime problem for you:
I very much doubt that you want to be setting the cell contents to the string representation of the collection (usually will come out as just the address of the collection in memory). You probably want to be storing your lValue (which is still a String) here.