ASF Bugzilla – Attachment 4661 Details for
Bug 9576
[PATCH] DBCELL, INDEX EXTSST (was Acess 97 import)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to allow Access, Word Mail Merge import the sheet
mailmerge.patch (text/plain), 14.87 KB, created by
Jason Height
on 2003-01-31 10:50:21 UTC
(
hide
)
Description:
Patch to allow Access, Word Mail Merge import the sheet
Filename:
MIME Type:
Creator:
Jason Height
Created:
2003-01-31 10:50:21 UTC
Size:
14.87 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.23 >diff -w -b -r1.23 Sheet.java >83c83 >< * @author Jason Height (jheight at chariot dot net dot au) Clone support >--- >> * @author Jason Height (jheight at chariot dot net dot au) Clone support. DBCell & Index Record writing support >601a602,604 >> * JMH I think that this method (hell maybe all of the serialize's that return a byte array) >> * can be removed... >> * >650c653 >< public int serialize(int offset, byte [] data) >--- >> public int serialize(final int offset, byte [] data) >654,669c657,658 >< // addDBCellRecords(); >< // ArrayList bytes = new ArrayList(4096); >< // int arraysize = getSize(); // 0; >< int pos = 0; >< >< // for (int k = 0; k < records.size(); k++) >< // { >< // bytes.add((( Record ) records.get(k)).serialize()); >< // >< // } >< // for (int k = 0; k < bytes.size(); k++) >< // { >< // arraysize += (( byte [] ) bytes.get(k)).length; >< // log.debug((new StringBuffer("arraysize=")).append(arraysize) >< // .toString()); >< // } >--- >> int pos = offset; >> boolean serializedIndex = false; >672,673d660 >< // byte[] rec = (( byte [] ) bytes.get(k)); >< // System.arraycopy(rec, 0, data, offset + pos, rec.length); >683c670,706 >< pos += record.serialize(pos + offset, data ); // rec.length; >--- >> //Once the rows have been found in the list of records, start >> //writing out the blocked row information. This includes the DBCell references >> if (record instanceof RowRecordsAggregate) { >> int blockCount = rows.getRowBlockCount(); >> >> for (int block=0;block<blockCount;block++) { >> //Serialize a block of rows. >> //Hold onto the position of the first row in the block >> final int rowStartPos = pos; >> //Hold onto the size of this block that was serialized >> final int rowBlockSize = rows.serializeRowBlock(block, pos, data); >> pos += rowBlockSize; >> //Serialize a block of cells for those rows >> final int startRowNumber = rows.getStartRowNumberOfBlock(block); >> final int endRowNumber = rows.getEndRowNumberOfBlock(block); >> DBCellRecord cellRecord = new DBCellRecord(); >> //Note: Cell references start from the second row... >> int cellRefOffset = (rowBlockSize-20); >> for (int row=startRowNumber;row<=endRowNumber;row++) { >> final int rowCellSize = cells.serializeCellRow(row, pos, data); >> pos += rowCellSize; >> //Add the offset to the first cell for the row into the DBCellRecord. >> cellRecord.addCellOffset((short)cellRefOffset); >> cellRefOffset = rowCellSize; >> } >> //Calculate Offset from the start of a DBCellRecord to the first Row >> cellRecord.setRowOffset(pos - rowStartPos); >> //We could add an assert here to check that prior to serialization >> //that the DBCell position matches the offset calculated by the index record >> //for this block. Would need to save a reference to the index record to do this. >> pos += cellRecord.serialize(pos, data); >> } >> } else if (record instanceof ValueRecordsAggregate) { >> //Do nothing here. The records were serialized during the RowRecordAggregate block serialization >> } else { >> pos += record.serialize(pos, data ); // rec.length; >> } >684a708,747 >> //If the BOF record was just serialized then add the IndexRecord >> if (record.getSid() == BOFRecord.sid) { >> //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 (!serializedIndex) { >> serializedIndex = true; >> IndexRecord index = new IndexRecord(); >> index.setFirstRow(rows.getFirstRowNum()); >> index.setLastRowAdd1(rows.getLastRowNum()+1); >> //Calculate the size of the records from the end of the BOF >> //and up to the RowRecordsAggregate... >> int sheetRecSize = 0; >> for (int j = k+1; j < records.size(); j++) >> { >> Record tmpRec = (( Record ) records.get(j)); >> if (tmpRec instanceof RowRecordsAggregate) >> break; >> sheetRecSize+= tmpRec.getRecordSize(); >> } >> //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 rowBlockOffset = 0; >> int cellBlockOffset = 0; >> int dbCellOffset = 0; >> for (int block=0;block<blockCount;block++) { >> rowBlockOffset += rows.getRowBlockSize(block); >> cellBlockOffset += cells.getRowCellBlockSize(rows.getStartRowNumberOfBlock(block), >> rows.getEndRowNumberOfBlock(block)); >> //Note: The offsets are relative to the Workbook BOF. Assume that this is >> //0 for now..... >> index.addDbcell(pos + indexRecSize + sheetRecSize + dbCellOffset + rowBlockOffset + cellBlockOffset); >> //Add space required to write the dbcell record(s) (whose references were just added). >> dbCellOffset += (8 + (rows.getRowCountForBlock(block) * 2)); >> } >> pos += index.serialize(pos, data); >> } >> } >687c750 >< return pos; >--- >> return pos-offset; >689a753 >> >2056a2121 >> >2057a2123,2137 >> >> } >> //Add space for the IndexRecord >> final int blocks = rows.getRowBlockCount(); >> retval += IndexRecord.getRecordSizeForBlockCount(blocks); >> >> //Add space for the DBCell records >> //Once DBCell per block. >> //8 bytes per DBCell (non variable section) >> //2 bytes per row reference >> retval += (8 * blocks); >> for (Iterator itr = rows.getIterator(); itr.hasNext();) { >> RowRecord row = (RowRecord)itr.next(); >> if (cells.rowHasCells(row.getRowNumber())) >> retval += 2; >2058a2139 >> >Index: src/java/org/apache/poi/hssf/model/Workbook.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/model/Workbook.java,v >retrieving revision 1.24 >diff -w -b -r1.24 Workbook.java >258a259 >> >Index: src/java/org/apache/poi/hssf/record/DBCellRecord.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/DBCellRecord.java,v >retrieving revision 1.4 >diff -w -b -r1.4 DBCellRecord.java >73a74 >> public final static int BLOCK_SIZE = 32; >220c221 >< LittleEndian.putShort(data, 8 + k + offset, getCellOffsetAt(k)); >--- >> LittleEndian.putShort(data, 8 + 2*k + offset, getCellOffsetAt(k)); >222a224,229 >> } >> >> /** Returns the size of the record when it needs to reference a certain >> * number of rows */ >> public static int getRecordSizeForRows(int rows) { >> return 8 + (rows * 2); >Index: src/java/org/apache/poi/hssf/record/IndexRecord.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/IndexRecord.java,v >retrieving revision 1.3 >diff -w -b -r1.3 IndexRecord.java >219a220,226 >> /** Returns the size of the IndexRecord given a number >> * of block (ie DBCell) references >> */ >> public static int getRecordSizeForBlockCount(int blockCount) { >> return 20 + (4 * blockCount); >> } >> >Index: src/java/org/apache/poi/hssf/record/RecordFactory.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/RecordFactory.java,v >retrieving revision 1.13 >diff -w -b -r1.13 RecordFactory.java >251a252 >> >282a284,291 >> //Ignore DBCell record, they are only used during serialization >> //and arent required for the reading process >> retval = null; >> } >> else if (retval instanceof IndexRecord) >> { >> //Ignore Index record, they are only used during serialization >> //and arent required for the reading process >Index: src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java,v >retrieving revision 1.4 >diff -w -b -r1.4 RowRecordsAggregate.java >57a58 >> import org.apache.poi.hssf.record.DBCellRecord; >137a139,222 >> /** Returns the number of row blocks. >> * The row blocks are groupings of rows that contain the DBCell record >> * at the end of them. >> */ >> public int getRowBlockCount() { >> int size = records.size()/DBCellRecord.BLOCK_SIZE; >> if ((records.size() % DBCellRecord.BLOCK_SIZE) != 0) >> size ++; >> return size; >> } >> >> /** Returns the size of the row records for a given block*/ >> public int getRowBlockSize(int block) { >> int startIndex = block * DBCellRecord.BLOCK_SIZE; >> int endIndex = startIndex + DBCellRecord.BLOCK_SIZE; >> if (endIndex >= records.size()) >> endIndex = records.size()-1; >> >> //The 20 is the (fixed) size of a RowRecord. >> return 20 * (endIndex-startIndex+1); >> } >> >> /** Returns the number of physical rows within a block*/ >> public int getRowCountForBlock(int block) { >> int startIndex = block * DBCellRecord.BLOCK_SIZE; >> int endIndex = startIndex + DBCellRecord.BLOCK_SIZE - 1; >> if (endIndex >= records.size()) >> endIndex = records.size()-1; >> >> return endIndex-startIndex+1; >> } >> >> /** Returns the physical row number of the first row in a block*/ >> public int getStartRowNumberOfBlock(int block) { >> //Damn! I would like to directly index a record in the map rather than >> //iterating through it. >> int startIndex = block * DBCellRecord.BLOCK_SIZE; >> Iterator rowIter = records.values().iterator(); >> RowRecord row = null; >> //Position the iterator at the start of the block >> for (int i=0; i<=startIndex;i++) { >> row = (RowRecord)rowIter.next(); >> } >> >> return row.getRowNumber(); >> } >> >> /** Returns the physical row number of the end row in a block*/ >> public int getEndRowNumberOfBlock(int block) { >> //Damn! I would like to directly index a record in the map rather than >> //iterating through it. >> int endIndex = ((block + 1)*DBCellRecord.BLOCK_SIZE)-1; >> if (endIndex >= records.size()) >> endIndex = records.size()-1; >> >> Iterator rowIter = records.values().iterator(); >> RowRecord row = null; >> for (int i=0; i<=endIndex;i++) { >> row = (RowRecord)rowIter.next(); >> } >> return row.getRowNumber(); >> } >> >> /** Serializes a block of rows */ >> public int serializeRowBlock(int block, int offset, byte [] data) >> { >> int startIndex = block * DBCellRecord.BLOCK_SIZE; >> int endIndex = startIndex + DBCellRecord.BLOCK_SIZE; >> >> Iterator itr = records.values().iterator(); >> int pos = offset; >> >> int i=0; >> for (; i<startIndex;i++) >> itr.next(); >> while (itr.hasNext() && (i++ < endIndex)) >> { >> pos += (( Record ) itr.next()).serialize(pos, data); >> } >> return pos - offset; >> } >> >> >> >Index: src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java,v >retrieving revision 1.6 >diff -w -b -r1.6 ValueRecordsAggregate.java >136a137,181 >> /** Tallies a count of the size of the cell records >> * that are attached to the rows in the range specified. >> */ >> public int getRowCellBlockSize(int startRow, int endRow) { >> //DAMN! It would be nice to be able to get a set of cells for a given row... >> Iterator cellRec = records.values().iterator(); >> int size = 0; >> while (cellRec.hasNext()) { >> CellValueRecordInterface cell = (CellValueRecordInterface)cellRec.next(); >> int row = cell.getRow(); >> if ((row >=startRow) && (row <= endRow)) >> size += ((Record)cell).getRecordSize(); >> } >> return size; >> } >> >> /** Returns true if the row has cells attached to it */ >> public boolean rowHasCells(int row) { >> //DAMN! It would be nice to be able to get a set of cells for a given row... >> Iterator cellRec = records.values().iterator(); >> int size = 0; >> while (cellRec.hasNext()) { >> CellValueRecordInterface cell = (CellValueRecordInterface)cellRec.next(); >> if (row ==cell.getRow()) >> return true; >> } >> return false; >> } >> >> /** Serializes the cells that are allocated to a certain row range*/ >> public int serializeCellRow(final int row, int offset, byte [] data) >> { >> //DAMN! It would be nice to be able to get a set of cells for a given row... >> Iterator itr = records.values().iterator(); >> int pos = offset; >> >> while (itr.hasNext()) >> { >> CellValueRecordInterface cell = (CellValueRecordInterface)itr.next(); >> if (row == cell.getRow()) >> pos += (( Record ) cell).serialize(pos, data); >> } >> return pos - offset; >> } >> >Index: src/java/org/apache/poi/hssf/util/Region.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/util/Region.java,v >retrieving revision 1.2 >diff -w -b -r1.2 Region.java >58c58 >< import org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion; >--- >> import org.apache.poi.hssf.record.MergeCellsRecord; >97c97 >< public Region(MergedRegion region) >--- >> public Region(MergeCellsRecord.MergedRegion region)
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 9576
: 4661 |
4717
|
5238
|
6514
|
6515