Java Mailing List Archive

http://www.java2.5341.com/

Home » user.poi »

How to update cell(s) in excel files ?

nileshkhavat

2008-09-30

Replies: Find Java Web Hosting

Author LoginPost Reply

------------------------------------------------------------------------------------
Hi,

I have a excel file with many sheets in it.
It has various formulas, dropdowns in it.
I have tried to update a cell in it by code.

       POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream("c:\\Try.xls"));
       HSSFWorkbook wb = new HSSFWorkbook(fs);
       HSSFSheet sheet = wb.getSheet("Try Sheet");
       HSSFRow row = sheet.getRow(3);
       HSSFCell cell = row.getCell((short) 2);

       if (cell == null) {
          cell = row.createCell((short) 2);
       }
       
       cell.setCellType(HSSFCell.CELL_TYPE_STRING);
       HSSFRichTextString str = new HSSFRichTextString("My Project
Name");
       cell.setCellValue(str);

       FileOutputStream fileOut = new FileOutputStream("c:\\Try.xls");
       wb.write(fileOut);
       fileOut.close();


After executing this excel file gets damaged.
It shows only text content.
All colors, drpdowns disapears.

Please suggest me the solution over it.

------------------------------------------------------------------------------------
--
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 java2.5341.com - Jax Systems, LLC, U.S.A.