Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Writing in existing excel(.xls) file

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi All,
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;

String filePath = //getting the filepath. ;
File file=new File(filePath);
FileInputStream fis=new FileInputStream(file);


HSSFWorkbook wb=new HSSFWorkbook(fis);
HSSFSheet st=wb.getSheet("Sheet1");
HSSFRow row=st.getRow(1);
HSSFCell cell= row.getCell(6);
cell.setCellValue(val);
fis.close();


This should write val to sheet1, row 1 cell 6 of the perticular excel that I'm passing. In filepath I'm passing file path along with file name.

But this is not working though not throwing any errors.
Could someone please help?
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
The FIS is used to create the HSSFWorkbook object.

I dont believe that changing cell values within the workbook object directly affects the FIS.

In my experiances with POI I have used xls files as a template but never had to ammend an existing file.

Perhaps close the current stream and write over the original file. I'm sure there is a more efficent way.

May I reccomend you use



instead of



Assuming sheet 1 is the first sheet in your workbook. You never know if you'll want to give the xls file a meaning full name and this will avoid you having to redeploy code.

 
harry ganguly
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks Joshua for pointing out the general way of pointing a sheetname.

Though this does not serve my requirement. If I go with your way, then the original file will be updated rather than getting updated. I just want to add one cell value rather than rewriting the file. So this is like append rather than overwrite

Could someone please give me some idea on this???
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Writing in existing excel(.xls) file

harry, please CarefullyChooseOneForum and UseOneThreadPerQuestion.

I'm locking this thread.
 
A teeny tiny vulgar attempt to get you to buy our stuff
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic