https://issues.apache.org/bugzilla/show_bug.cgi?id=46885
Summary: [Patch] - setting cached formula result corrupts
workbook
Product: POI
Version: 3.5-dev
Platform: All
URL: http://mail-archives.apache.org/mod_mbox/poi-user/2009
03.mbox/<[email protected]>
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: XSSF
AssignedTo: [email protected]
ReportedBy: [email protected]
This bug was created due to the poi-user posting by Paul Dobson on Mar 20.
The following code will cause Excel to report the workbook as corrupted, and
attempt a repair on it:
String xlsxFilePath = "empty.xlsx";
FileInputStream in = new FileInputStream(xlsxFilePath);
Workbook wb = WorkbookFactory.create(in);
Sheet sh = wb.getSheet("Sheet1");
Row row = sh.createRow(1);
Cell cell = row.createCell(1);
cell.setCellFormula("NA()");
cell.setCellValue("Help, I will not change!"); //corrupts workbook
in.close();
FileOutputStream out = new FileOutputStream("out.xlsx");
wb.write(out);
out.close();
With some investigation, I found that Excel is missing the type attribute from
the following XML fragment:
<c r="B2">
<f>NA()</f>
<v>Help, I will not change!</v>
</c>
By adding 't="str"' (as follows) the workbook opens properly.
<c r="B2" t="str">
<f>NA()</f>
<v>Help, I will not change!</v>
</c>
Here is a patch that seems to have the desired effect. Can someone review
please?
$ svn diff src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
===================================================================
--- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (revision
755692 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=755692 ))
+++ src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (working copy)
@@ -217,6 +217,7 @@
case CELL_TYPE_ERROR:
case CELL_TYPE_FORMULA:
cell.setV(String.valueOf(value));
+ cell.setT(STCellType.N);
break;
default:
cell.setT(STCellType.N);
@@ -303,6 +304,7 @@
switch(cellType){
case Cell.CELL_TYPE_FORMULA:
cell.setV(str.getString());
+ cell.setT(STCellType.STR);
break;
default:
if(cell.getT() == STCellType.INLINE_STR) {
--
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]