use of org.apache.poi.hssf.record.MergeCellsRecord in project poi by apache.
the class MergedCellsTable method read.
/**
* reads zero or more consecutive {@link MergeCellsRecord}s
* @param rs
*/
public void read(RecordStream rs) {
List<CellRangeAddress> temp = _mergedRegions;
while (rs.peekNextClass() == MergeCellsRecord.class) {
MergeCellsRecord mcr = (MergeCellsRecord) rs.getNext();
int nRegions = mcr.getNumAreas();
for (int i = 0; i < nRegions; i++) {
CellRangeAddress cra = mcr.getAreaAt(i);
temp.add(cra);
}
}
}
use of org.apache.poi.hssf.record.MergeCellsRecord in project poi by apache.
the class MergedCellsTable method visitContainedRecords.
public void visitContainedRecords(RecordVisitor rv) {
int nRegions = _mergedRegions.size();
if (nRegions < 1) {
// no need to write a single empty MergeCellsRecord
return;
}
int nFullMergedCellsRecords = nRegions / MAX_MERGED_REGIONS;
int nLeftoverMergedRegions = nRegions % MAX_MERGED_REGIONS;
CellRangeAddress[] cras = new CellRangeAddress[nRegions];
_mergedRegions.toArray(cras);
for (int i = 0; i < nFullMergedCellsRecords; i++) {
int startIx = i * MAX_MERGED_REGIONS;
rv.visitRecord(new MergeCellsRecord(cras, startIx, MAX_MERGED_REGIONS));
}
if (nLeftoverMergedRegions > 0) {
int startIx = nFullMergedCellsRecords * MAX_MERGED_REGIONS;
rv.visitRecord(new MergeCellsRecord(cras, startIx, nLeftoverMergedRegions));
}
}
use of org.apache.poi.hssf.record.MergeCellsRecord in project poi by apache.
the class TestSheet method testMovingMergedRegion.
/**
* Bug: 22922 (Reported by Xuemin Guan)
* <p>
* Remove mergedregion fails when a sheet loses records after an initial CreateSheet
* fills up the records.
*
*/
@Test
public void testMovingMergedRegion() {
List<Record> records = new ArrayList<Record>();
CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2) };
MergeCellsRecord merged = new MergeCellsRecord(cras, 0, cras.length);
records.add(BOFRecord.createSheetBOF());
records.add(new DimensionsRecord());
records.add(new RowRecord(0));
records.add(new RowRecord(1));
records.add(new RowRecord(2));
records.add(createWindow2Record());
records.add(EOFRecord.instance);
records.add(merged);
InternalSheet sheet = createSheet(records);
// TODO - what does this line do?
sheet.getRecords().remove(0);
//stub object to throw off list INDEX operations
sheet.removeMergedRegion(0);
assertEquals("Should be no more merged regions", 0, sheet.getNumMergedRegions());
}
Aggregations