ASF Bugzilla – Attachment 21392 Details for
Bug 44233
[PATCH] New record 0x5E UncalcedRecord
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch file
uncalced.patch (text/plain), 5.75 KB, created by
Olivier Leprince
on 2008-01-14 17:37:08 UTC
(
hide
)
Description:
Patch file
Filename:
MIME Type:
Creator:
Olivier Leprince
Created:
2008-01-14 17:37:08 UTC
Size:
5.75 KB
patch
obsolete
>Index: src/java/org/apache/poi/hssf/model/Sheet.java >=================================================================== >--- src/java/org/apache/poi/hssf/model/Sheet.java (revision 611941) >+++ src/java/org/apache/poi/hssf/model/Sheet.java (working copy) >@@ -97,6 +97,8 @@ > protected ScenarioProtectRecord scenprotect = null; > protected PasswordRecord password = null; > >+ /** Add an UncalcedRecord if not true indicating formulas have not been calculated */ >+ protected boolean uncalced = false; > > public static final byte PANE_LOWER_RIGHT = (byte)0; > public static final byte PANE_UPPER_RIGHT = (byte)1; >@@ -747,6 +749,11 @@ > } > //If the BOF record was just serialized then add the IndexRecord > if (record.getSid() == BOFRecord.sid) { >+ // Add an optional UncalcedRecord >+ if (uncalced) { >+ UncalcedRecord rec = new UncalcedRecord(); >+ pos += rec.serialize(pos, data); >+ } > //Can there be more than one BOF for a sheet? If not then we can > //remove this guard. So be safe it is left here. > if (rows != null && !haveSerializedIndex) { >@@ -2184,6 +2191,11 @@ > retval += 2; > } > } >+ // Add space for UncalcedRecord >+ if (uncalced) { >+ retval += UncalcedRecord.getStaticRecordSize(); >+ } >+ > return retval; > } > >@@ -2651,8 +2663,22 @@ > public boolean isDisplayRowColHeadings() { > return windowTwo.getDisplayRowColHeadings(); > } >+ > > /** >+ * @return whether an uncalced record must be inserted or not at generation >+ */ >+ public boolean getUncalced() { >+ return uncalced; >+ } >+ /** >+ * @param uncalced whether an uncalced record must be inserted or not at generation >+ */ >+ public void setUncalced(boolean uncalced) { >+ this.uncalced = uncalced; >+ } >+ >+ /** > * Returns the array of margins. If not created, will create. > * > * @return the array of marings. >Index: src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (revision 611941) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (working copy) >@@ -595,6 +595,26 @@ > } > > /** >+ * Whether a record must be inserted or not at generation to indicate that >+ * formula must be recalculated when workbook is opened. >+ * @param value true if an uncalced record must be inserted or not at generation >+ */ >+ public void setForceFormulaRecalculation(boolean value) >+ { >+ sheet.setUncalced(value); >+ } >+ /** >+ * Whether a record must be inserted or not at generation to indicate that >+ * formula must be recalculated when workbook is opened. >+ * @return true if an uncalced record must be inserted or not at generation >+ */ >+ public boolean getForceFormulaRecalculation() >+ { >+ return sheet.getUncalced(); >+ } >+ >+ >+ /** > * determines whether the output is vertically centered on the page. > * @param value true to vertically center, false otherwise. > */ >Index: src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java >=================================================================== >--- src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (revision 611941) >+++ src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (working copy) >@@ -19,14 +19,18 @@ > > package org.apache.poi.hssf.usermodel; > >-import java.io.*; >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.FileOutputStream; > > import junit.framework.TestCase; > > import org.apache.poi.hssf.model.Sheet; > import org.apache.poi.hssf.record.HCenterRecord; >+import org.apache.poi.hssf.record.PasswordRecord; > import org.apache.poi.hssf.record.ProtectRecord; >-import org.apache.poi.hssf.record.PasswordRecord; > import org.apache.poi.hssf.record.SCLRecord; > import org.apache.poi.hssf.record.VCenterRecord; > import org.apache.poi.hssf.record.WSBoolRecord; >@@ -790,7 +794,40 @@ > assertTrue(sheet3.getColumnWidth((short)0) <= maxWithRow1And2); > } > >- public static void main(java.lang.String[] args) { >+ /** >+ * Setting ForceFormulaRecalculation on sheets >+ */ >+ public void testForceRecalculation() throws Exception { >+ String filename = System.getProperty("HSSF.testdata.path"); >+ filename = filename + "/UncalcedRecord.xls"; >+ HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filename)); >+ >+ HSSFSheet sheet = workbook.getSheetAt(0); >+ HSSFRow row = sheet.getRow(0); >+ row.createCell((short) 0).setCellValue(5); >+ row.createCell((short) 1).setCellValue(8); >+ >+ // Save and manually verify that on column C we have 0, value in template >+ File tempFile = new File(System.getProperty("java.io.tmpdir")+"/uncalced_err.xls" ); >+ tempFile.delete(); >+ FileOutputStream fout = new FileOutputStream( tempFile ); >+ workbook.write( fout ); >+ fout.close(); >+ sheet.setForceFormulaRecalculation(true); >+ >+ // Save and manually verify that on column C we have now 13, calculated value >+ tempFile = new File(System.getProperty("java.io.tmpdir")+"/uncalced_succ.xls" ); >+ tempFile.delete(); >+ fout = new FileOutputStream( tempFile ); >+ workbook.write( fout ); >+ fout.close(); >+ >+ // Try it can be opened >+ HSSFWorkbook wb2 = new HSSFWorkbook(new FileInputStream(tempFile)); >+ } >+ >+ >+ public static void main(java.lang.String[] args) { > junit.textui.TestRunner.run(TestHSSFSheet.class); > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 44233
: 21392 |
21393
|
21395