You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by nileshkhavat <ni...@yahoo.co.in> on 2008/09/30 11:01:13 UTC

How to update cell(s) in excel files ?

------------------------------------------------------------------------------------
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.

------------------------------------------------------------------------------------ 
-- 
View this message in context: http://www.nabble.com/How-to-update-cell%28s%29-in-excel-files---tp19738477p19738477.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: How to update cell(s) in excel files ?

Posted by Anthony Andrews <py...@yahoo.com>.
I have no idea what the problem may be - I do not have the Excel file at hand - but suspect there is some feature of the workbook HSSF is unsure about. As a test can you use HSSF to simply create a copy of the workbook - open it and then save it to a new name/location then see if HSSF has similarly mangled the file?

--- On Sat, 10/4/08, nileshkhavat <ni...@yahoo.co.in> wrote:
From: nileshkhavat <ni...@yahoo.co.in>
Subject: Re: How to update cell(s) in excel files ?
To: user@poi.apache.org
Date: Saturday, October 4, 2008, 12:28 AM

Hi,

I have also used objects in the sheet.


nileshkhavat wrote:
> 
>
------------------------------------------------------------------------------------
> Hi,
> 
> I have a excel file with many sheets in it.
> It has various formulas, colors and dropdowns in it.
> Colors and dropdowns are populated by VB MACROS. 
> 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 above code following happens
>    -excel file gets damaged.
>    -it shows only text contents in sheet.
>    -all colors, dropdowns disapears in sheet.
>    -some sheets totally absent.
> 
> Please suggest me the solution over it.
> 
>
------------------------------------------------------------------------------------

> 

-- 
View this message in context:
http://www.nabble.com/How-to-update-cell%28s%29-in-excel-files---tp19738477p19809753.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org




      

Re: How to update cell(s) in excel files ?

Posted by nileshkhavat <ni...@yahoo.co.in>.
Hi,

I have also used objects in the sheet.


nileshkhavat wrote:
> 
> ------------------------------------------------------------------------------------
> Hi,
> 
> I have a excel file with many sheets in it.
> It has various formulas, colors and dropdowns in it.
> Colors and dropdowns are populated by VB MACROS. 
> 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 above code following happens
>    -excel file gets damaged.
>    -it shows only text contents in sheet.
>    -all colors, dropdowns disapears in sheet.
>    -some sheets totally absent.
> 
> Please suggest me the solution over it.
> 
> ------------------------------------------------------------------------------------ 
> 

-- 
View this message in context: http://www.nabble.com/How-to-update-cell%28s%29-in-excel-files---tp19738477p19809753.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org