ASF Bugzilla – Attachment 15719 Details for
Bug 35799
New cell in a column that has specific formatting should retain formatting in the cell
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
[PATCH] changes to Sheet, HSSFCell
35799.patch (text/plain), 7.60 KB, created by
Amol Deshmukh
on 2005-07-20 16:16:34 UTC
(
hide
)
Description:
[PATCH] changes to Sheet, HSSFCell
Filename:
MIME Type:
Creator:
Amol Deshmukh
Created:
2005-07-20 16:16:34 UTC
Size:
7.60 KB
patch
obsolete
>Index: src/java/org/apache/poi/hssf/model/Sheet.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/model/Sheet.java,v >retrieving revision 1.55 >diff -u -r1.55 Sheet.java >--- src/java/org/apache/poi/hssf/model/Sheet.java 31 May 2005 19:03:19 -0000 1.55 >+++ src/java/org/apache/poi/hssf/model/Sheet.java 20 Jul 2005 14:06:04 -0000 >@@ -822,7 +822,7 @@ > //Add the references to the DBCells in the IndexRecord (one for each block) > int blockCount = rows.getRowBlockCount(); > //Calculate the size of this IndexRecord >- int indexRecSize = index.getRecordSizeForBlockCount(blockCount); >+ int indexRecSize = IndexRecord.getRecordSizeForBlockCount(blockCount); > > int rowBlockOffset = 0; > int cellBlockOffset = 0; >@@ -1833,6 +1833,37 @@ > } > return retval; > } >+ >+ /** >+ * get the index to the ExtendedFormatRecord "associated" with >+ * the column at specified 0-based index. (In this case, an >+ * ExtendedFormatRecord index is actually associated with a >+ * ColumnInfoRecord which spans 1 or more columns) >+ * <br/> >+ * Returns the index to the default ExtendedFormatRecord (0xF) >+ * if no ColumnInfoRecord exists that includes the column >+ * index specified. >+ * @param column >+ * @return index of ExtendedFormatRecord associated with >+ * ColumnInfoRecord that includes the column index or the >+ * index of the default ExtendedFormatRecord (0xF) >+ */ >+ public short getXFIndexForColAt(short column) { >+ short retval = 0; >+ ColumnInfoRecord ci = null; >+ if (columns != null) { >+ for (Iterator iterator = columns.getIterator(); iterator.hasNext();) { >+ ci = (ColumnInfoRecord) iterator.next(); >+ if ((ci.getFirstColumn() <= column) >+ && (column <= ci.getLastColumn())) { >+ break; >+ } >+ ci = null; >+ } >+ } >+ retval = (ci != null) ? ci.getXFIndex() : 0xF; >+ return retval; >+ } > > /** > * set the width for a given column in 1/20th of a character width units >Index: src/java/org/apache/poi/hssf/usermodel/HSSFCell.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java,v >retrieving revision 1.30 >diff -u -r1.30 HSSFCell.java >--- src/java/org/apache/poi/hssf/usermodel/HSSFCell.java 20 May 2005 09:13:14 -0000 1.30 >+++ src/java/org/apache/poi/hssf/usermodel/HSSFCell.java 20 Jul 2005 14:06:04 -0000 >@@ -31,7 +31,6 @@ > import org.apache.poi.hssf.record.formula.Ptg; > > import java.text.DateFormat; >-import java.text.DecimalFormat; > import java.text.SimpleDateFormat; > import java.util.Calendar; > import java.util.Date; >@@ -155,9 +154,10 @@ > // is different to CELL_TYPE_BLANK hence the following method call correctly > // creates a new blank cell. > setCellType(CELL_TYPE_BLANK, false); >- ExtendedFormatRecord xf = book.getExFormatAt(0xf); >- >- setCellStyle(new HSSFCellStyle(( short ) 0xf, xf)); >+ >+ short xfindex = sheet.getXFIndexForColAt(col); >+ ExtendedFormatRecord xf = book.getExFormatAt(xfindex); >+ setCellStyle(new HSSFCellStyle(xfindex, xf)); > } > > /** >@@ -238,7 +238,9 @@ > (( BoolErrRecord ) record).setValue(( byte ) 0); > break; > } >- ExtendedFormatRecord xf = book.getExFormatAt(0xf); >+ >+ int xfindex = sheet.getXFIndexForColAt(col); >+ ExtendedFormatRecord xf = book.getExFormatAt(xfindex); > > setCellStyle(new HSSFCellStyle(( short ) 0xf, xf)); > } >Index: src/testcases/org/apache/poi/hssf/model/TestSheet.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/hssf/model/TestSheet.java,v >retrieving revision 1.3 >diff -u -r1.3 TestSheet.java >--- src/testcases/org/apache/poi/hssf/model/TestSheet.java 1 May 2005 11:26:18 -0000 1.3 >+++ src/testcases/org/apache/poi/hssf/model/TestSheet.java 20 Jul 2005 14:06:05 -0000 >@@ -280,5 +280,77 @@ > assertEquals("no more breaks", 0, sheet.getNumColumnBreaks()); > } > >+ /** >+ * test newly added method Sheet.getXFIndexForColAt(..) >+ * works as designed. >+ */ >+ public void testXFIndexForColumn() { >+ try{ >+ final short TEST_IDX = 10; >+ final short DEFAULT_IDX = 0xF; // 15 >+ short xfindex = Short.MIN_VALUE; >+ Sheet sheet = Sheet.createSheet(); >+ >+ // without ColumnInfoRecord >+ xfindex = sheet.getXFIndexForColAt((short) 0); >+ assertEquals(DEFAULT_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 1); >+ assertEquals(DEFAULT_IDX, xfindex); >+ >+ ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo(); >+ sheet.columns.insertColumn(nci); >+ >+ // single column ColumnInfoRecord >+ nci.setFirstColumn((short) 2); >+ nci.setLastColumn((short) 2); >+ nci.setXFIndex(TEST_IDX); >+ xfindex = sheet.getXFIndexForColAt((short) 0); >+ assertEquals(DEFAULT_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 1); >+ assertEquals(DEFAULT_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 2); >+ assertEquals(TEST_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 3); >+ assertEquals(DEFAULT_IDX, xfindex); >+ >+ // ten column ColumnInfoRecord >+ nci.setFirstColumn((short) 2); >+ nci.setLastColumn((short) 11); >+ nci.setXFIndex(TEST_IDX); >+ xfindex = sheet.getXFIndexForColAt((short) 1); >+ assertEquals(DEFAULT_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 2); >+ assertEquals(TEST_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 6); >+ assertEquals(TEST_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 11); >+ assertEquals(TEST_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 12); >+ assertEquals(DEFAULT_IDX, xfindex); >+ >+ // single column ColumnInfoRecord starting at index 0 >+ nci.setFirstColumn((short) 0); >+ nci.setLastColumn((short) 0); >+ nci.setXFIndex(TEST_IDX); >+ xfindex = sheet.getXFIndexForColAt((short) 0); >+ assertEquals(TEST_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 1); >+ assertEquals(DEFAULT_IDX, xfindex); >+ >+ // ten column ColumnInfoRecord starting at index 0 >+ nci.setFirstColumn((short) 0); >+ nci.setLastColumn((short) 9); >+ nci.setXFIndex(TEST_IDX); >+ xfindex = sheet.getXFIndexForColAt((short) 0); >+ assertEquals(TEST_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 7); >+ assertEquals(TEST_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 9); >+ assertEquals(TEST_IDX, xfindex); >+ xfindex = sheet.getXFIndexForColAt((short) 10); >+ assertEquals(DEFAULT_IDX, xfindex); >+ } >+ catch(Exception e){e.printStackTrace();fail(e.getMessage());} >+ } > > }
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 35799
: 15719