ASF Bugzilla – Attachment 3335 Details for
Bug 13248
[Patch] HSSF does not save user defined number formats
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to add functionality to FormatRecord and test case to ensure it doesn't disappear
patch2.txt (text/plain), 5.01 KB, created by
Shawn Laubach
on 2002-10-03 15:27:05 UTC
(
hide
)
Description:
Patch to add functionality to FormatRecord and test case to ensure it doesn't disappear
Filename:
MIME Type:
Creator:
Shawn Laubach
Created:
2002-10-03 15:27:05 UTC
Size:
5.01 KB
patch
obsolete
>Index: src/java/org/apache/poi/hssf/record/FormatRecord.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/FormatRecord.java,v >retrieving revision 1.5 >diff -u -r1.5 FormatRecord.java >--- src/java/org/apache/poi/hssf/record/FormatRecord.java 2 Sep 2002 02:11:15 -0000 1.5 >+++ src/java/org/apache/poi/hssf/record/FormatRecord.java 3 Oct 2002 15:17:05 -0000 >@@ -64,6 +64,7 @@ > * > * REFERENCE: PG 317 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> > * @author Andrew C. Oliver (acoliver at apache dot org) >+ * @author Shawn M. Laubach (shawnlaubach at cox dot net) > * @version 2.0-pre > */ > >@@ -72,7 +73,7 @@ > { > public final static short sid = 0x41e; > private short field_1_index_code; >- private byte field_2_formatstring_len; >+ private short field_2_formatstring_len; > private short field_3_unicode_len; // unicode string length > private boolean field_3_unicode_flag; // it is not undocumented - it is unicode flag > private String field_4_formatstring; >@@ -121,6 +122,7 @@ > field_1_index_code = LittleEndian.getShort(data, 0 + offset); > // field_2_formatstring_len = data[ 2 + offset ]; > field_3_unicode_len = LittleEndian.getShort( data, 2 + offset ); >+ field_2_formatstring_len = field_3_unicode_len; > field_3_unicode_flag = ( data[ 4 + offset ] & (byte)0x01 ) != 0; > > >@@ -156,6 +158,17 @@ > public void setFormatStringLength(byte len) > { > field_2_formatstring_len = len; >+ field_3_unicode_len = len; >+ } >+ >+ /** >+ * set whether the string is unicode >+ * >+ * @param unicode flag for whether string is unicode >+ */ >+ >+ public void setUnicodeFlag(boolean unicode) { >+ field_3_unicode_flag = unicode; > } > > /** >@@ -189,10 +202,20 @@ > * @see #getFormatString() > */ > >- public byte getFormatStringLength() >+ public short getFormatStringLength() > { >- return field_2_formatstring_len; >+ return field_3_unicode_flag ? field_3_unicode_len : field_2_formatstring_len; > } >+ >+ /** >+ * get whether the string is unicode >+ * >+ * @return flag for whether string is unicode >+ */ >+ >+ public boolean getUnicodeFlag() { >+ return field_3_unicode_flag; >+ } > > /** > * get the format string >Index: src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java,v >retrieving revision 1.6 >diff -u -r1.6 TestWorkbook.java >--- src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java 11 Sep 2002 02:30:43 -0000 1.6 >+++ src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java 3 Oct 2002 15:17:07 -0000 >@@ -253,9 +253,57 @@ > sheet.getRow(( short ) 0).getCell(( short ) 0); > > assertEquals(1.25,cell.getNumericCellValue(), 1e-10); >- > > assertEquals(format.getFormat(cell.getCellStyle().getDataFormat()), "0.0"); >+ stream.close(); >+ } >+ >+/** >+ * TEST NAME: Test Read/Write Simple w/ Data Format<P> >+ * OBJECTIVE: Test that HSSF can write a sheet with custom data formats and then read it and get the proper formats.<P> >+ * SUCCESS: HSSF reads the sheet. Matches values in their particular positions and format is correct<P> >+ * FAILURE: HSSF does not read a sheet or excepts. HSSF cannot identify values >+ * in the sheet in their known positions.<P> >+ * >+ */ >+ >+ public void testWriteDataFormat() >+ throws IOException >+ { >+ File file = File.createTempFile("testWriteDataFormat", >+ ".xls"); >+ System.err.println(file); >+ FileOutputStream out = new FileOutputStream(file); >+ HSSFWorkbook wb = new HSSFWorkbook(); >+ HSSFSheet s = wb.createSheet(); >+ HSSFRow r = null; >+ HSSFCell c = null; >+ HSSFDataFormat format = wb.createDataFormat(); >+ HSSFCellStyle cs = wb.createCellStyle(); >+ >+ short df = format.getFormat("0.0"); >+ cs.setDataFormat(df); >+ >+ r = s.createRow((short)0); >+ c = r.createCell((short)0); >+ c.setCellStyle(cs); >+ c.setCellValue(1.25); >+ >+ wb.write(out); >+ out.close(); >+ >+ FileInputStream stream = new FileInputStream(file); >+ POIFSFileSystem fs = new POIFSFileSystem(stream); >+ HSSFWorkbook workbook = new HSSFWorkbook(fs); >+ HSSFSheet sheet = workbook.getSheetAt(0); >+ HSSFCell cell = >+ sheet.getRow(( short ) 0).getCell(( short ) 0); >+ format = workbook.createDataFormat(); >+ >+ assertEquals(1.25,cell.getNumericCellValue(), 1e-10); >+ >+ assertEquals(format.getFormat(df), "0.0"); >+ > stream.close(); > } >
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 13248
: 3335