Search in sources :

Example 1 with MergeCellsRecord

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);
        }
    }
}
Also used : MergeCellsRecord(org.apache.poi.hssf.record.MergeCellsRecord) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 2 with MergeCellsRecord

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));
    }
}
Also used : MergeCellsRecord(org.apache.poi.hssf.record.MergeCellsRecord) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 3 with MergeCellsRecord

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());
}
Also used : RowRecord(org.apache.poi.hssf.record.RowRecord) MergeCellsRecord(org.apache.poi.hssf.record.MergeCellsRecord) ArrayList(java.util.ArrayList) StringRecord(org.apache.poi.hssf.record.StringRecord) GutsRecord(org.apache.poi.hssf.record.GutsRecord) MergeCellsRecord(org.apache.poi.hssf.record.MergeCellsRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) Record(org.apache.poi.hssf.record.Record) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) IndexRecord(org.apache.poi.hssf.record.IndexRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) UncalcedRecord(org.apache.poi.hssf.record.UncalcedRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Test(org.junit.Test)

Aggregations

MergeCellsRecord (org.apache.poi.hssf.record.MergeCellsRecord)3 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)3 ArrayList (java.util.ArrayList)1 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)1 BOFRecord (org.apache.poi.hssf.record.BOFRecord)1 BlankRecord (org.apache.poi.hssf.record.BlankRecord)1 ColumnInfoRecord (org.apache.poi.hssf.record.ColumnInfoRecord)1 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)1 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)1 EOFRecord (org.apache.poi.hssf.record.EOFRecord)1 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)1 GutsRecord (org.apache.poi.hssf.record.GutsRecord)1 IndexRecord (org.apache.poi.hssf.record.IndexRecord)1 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)1 NoteRecord (org.apache.poi.hssf.record.NoteRecord)1 NumberRecord (org.apache.poi.hssf.record.NumberRecord)1 ObjRecord (org.apache.poi.hssf.record.ObjRecord)1 Record (org.apache.poi.hssf.record.Record)1 RowRecord (org.apache.poi.hssf.record.RowRecord)1 StringRecord (org.apache.poi.hssf.record.StringRecord)1