I want to write in an existing excel(in sheet1) file in a perticular cell(say row=1,cell=6). I'm using poi jar. But I could not write in that perticular cell.
String val= //value that I want to write;
Modifying the file you have read in is simple. You retrieve the object via an assessor method, remove it via a parent object's remove method (sheet.removeRow(hssfrow)) and create objects just as you would if creating a new xls. When you are done modifying cells just call workbook.write(outputstream)
So basically the suggestion you have been given IS the solution that the makers of the POI library are also giving. Regardless of processes involved the outcome is still the same.
Overwriting the existing file and updating the existing file are the same thing. You seem to see a distinction where none exists.
Ping & DNS - updated with new look and Ping home screen widget
Joined: Dec 14, 2010
@Wim: I could not find the perticular value in cell(1:6) after fis.close(). Your understanding is right.
@Ulf: Whatever it may be, I want to have cell(1,6) value="x" without hampering other cells values.
Is there anyway I can do it?Can anyone tell me some way to do so??
Is it just me or has anyone else noticed that the code will not write anything because it uses a FileInputStream only?
At least I think it won't write anything, might be I'm just missing something here...
Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
harry ganguly wrote:Is there anyway I can do it?Can anyone tell me some way to do so??
Take a careful look at all the steps that are taken in the code example I copied here from the POI quick guide.
1. open a file (with a certain path and filename)
2. create a workbook from it
3. navigate to the cell
4. create the cell if it doesn't exist yet
5. fill the cell with a value (of type x)
6. write the workbook to a file (to that same path and with the same filename; overwrite)
If you omit step 6 the update of the cell will never 'persist', will never be saved to the file. The new value will be available in memory though. As the following code demonstrates:
As pointed out by Jan Hoppman: FileInputStream will not be enough to have your update written to the file.
Joined: Dec 14, 2010
@Jan: FileOuputStream will create a new wb....which is not my reqmnt.
I doubt it is the purpose of this forum to be a code generator, even though examples will in most cases clarify things. I get the feeling that in this case you can easily find the information you're looking for from the JExcelApi website. It is a different API so you will have to adapt your code accordingly. Most likely cell.SetCellValue(val) will have to be replaced by something else.
Let the tutorial guide you; if you get in trouble with the code while following the tutorial, I'm sure there's enough helpful hands around to get you on your way.
And a last little tap on the fingers: don't let a small hiccup with one API force you to go to the next one so soon. I feel that we have given quite a lot of pointers as to how to solve your initial problem. If you don't get a grip on that problem while using POI, chances are you won't get a grip with JExcelApi either.