You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Dipen Javia <di...@gmail.com> on 2007/10/31 15:22:57 UTC

adding a row to excel file

I have a following code where I am trying to add a value to an existing
sheet. But for some reason, it works on some cells and it doesnt for others.
I think its a format issue how do i know the format of the cell and figure
out the format setting?

try {
        String filename = "C:/m/util.xls";
        POIFSFileSystem fs  = new POIFSFileSystem(new
FileInputStream(filename));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt((short)0);
        int i = 17;
        HSSFRow row = sheet.getRow(i);
        HSSFCell cell = row.getCell((short) 1);
        cell.setCellValue("test!");
        FileOutputStream fileOut = new FileOutputStream(filename);
        fileOut = new FileOutputStream(filename);
        wb.write(fileOut);
        fileOut.close();
        }catch(Exception e) { e.printStackTrace(); }

some of the cells have same formatting but still it works on some cells and
it doesnt on others.

Re: adding a row to excel file

Posted by Anthony Andrews <py...@yahoo.com>.
Are you saying that after you insert the 'new' value into the cell the formatting that had previously been applied to that cell is lost?

If so, then you need to read the existing formatting from the cell and store it into a local variable, change the cell's value and then re-apply the formatting that you read.

Dipen Javia <di...@gmail.com> wrote: I have a following code where I am trying to add a value to an existing
sheet. But for some reason, it works on some cells and it doesnt for others.
I think its a format issue how do i know the format of the cell and figure
out the format setting?

try {
        String filename = "C:/m/util.xls";
        POIFSFileSystem fs  = new POIFSFileSystem(new
FileInputStream(filename));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt((short)0);
        int i = 17;
        HSSFRow row = sheet.getRow(i);
        HSSFCell cell = row.getCell((short) 1);
        cell.setCellValue("test!");
        FileOutputStream fileOut = new FileOutputStream(filename);
        fileOut = new FileOutputStream(filename);
        wb.write(fileOut);
        fileOut.close();
        }catch(Exception e) { e.printStackTrace(); }

some of the cells have same formatting but still it works on some cells and
it doesnt on others.


 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com