https://issues.apache.org/bugzilla/show_bug.cgi?id=46535


Yegor Kozlov <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




--- Comment #10 from Yegor Kozlov <[email protected]>  2009-02-08 05:24:19 PST ---
You are not supposed to call setCellType directly, instead setCellValue(String)
does it for you behind the scene.

There are two possible scenarios when setting value for a formula cell;

 1. Update the precalculated value of the formula.
 If a cell contains formula then cell.setCellValue just updates the
precalculated formula value, 
 the formula iself remains and the cell type is not changed:

        XSSFWorkbook wb = new XSSFWorkbook("original.xlsx");
        XSSFSheet sheet = wb.getSheet("Test");
        XSSFRow row = sheet.getRow(0);
        XSSFCell cell = row.getCell(4);
        cell.setCellValue("ABC"); //only update the precalculated formula
value, the cell type remains CELL_TYPE_FORMULA.
        FileOutputStream output = new FileOutputStream("output.xlsx");
        wb.write(output);
        output.close();

 2. Remove the formula and change the cell type to String or Number:

        XSSFWorkbook wb = new XSSFWorkbook("original.xlsx");
        XSSFSheet sheet = wb.getSheet("Test");
        XSSFRow row = sheet.getRow(0);
        XSSFCell cell = row.getCell(4);
        cell.setCellFormula(null); //Remove the formula
        cell.setCellValue("ABC"); //set the string value, the cell type is
changed to CELL_TYPE_STRING
        FileOutputStream output = new FileOutputStream("output.xlsx");
        wb.write(output);
        output.close();


Excel 2007 files can contain supplementary data called Calculation Chain. This
object specifies the order in which the cells in a workbook were last
calculated. It turns out that when a formula is deleted we need to remove all
references to it from the calculation chain, otherwise the resulting file
cannot be opened.
This problem was fixed in r742077 ( 
https://svn.apache.org/viewcvs.cgi?view=rev&rev=742077 )

Regards,
Yegor


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to