Search in sources :

Example 11 with ColumnInfoRecord

use of org.apache.poi.hssf.record.ColumnInfoRecord in project poi by apache.

the class TestColumnInfoRecordsAggregate method createColInfo.

private static ColumnInfoRecord createColInfo(int firstCol, int lastCol) {
    ColumnInfoRecord columnInfoRecord = new ColumnInfoRecord();
    columnInfoRecord.setFirstColumn((short) firstCol);
    columnInfoRecord.setLastColumn((short) lastCol);
    return columnInfoRecord;
}
Also used : ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord)

Example 12 with ColumnInfoRecord

use of org.apache.poi.hssf.record.ColumnInfoRecord in project poi by apache.

the class TestColumnInfoRecordsAggregate method testGroupColumns_bug45639.

@Test
public void testGroupColumns_bug45639() {
    ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
    agg.groupColumnRange(7, 9, true);
    agg.groupColumnRange(4, 12, true);
    try {
        agg.groupColumnRange(1, 15, true);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new AssertionFailedError("Identified bug 45639");
    }
    ColumnInfoRecord[] cirs = CIRCollector.getRecords(agg);
    assertEquals(5, cirs.length);
    confirmCIR(cirs, 0, 1, 3, 1, false, false);
    confirmCIR(cirs, 1, 4, 6, 2, false, false);
    confirmCIR(cirs, 2, 7, 9, 3, false, false);
    confirmCIR(cirs, 3, 10, 12, 2, false, false);
    confirmCIR(cirs, 4, 13, 15, 1, false, false);
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError) ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord) Test(org.junit.Test)

Example 13 with ColumnInfoRecord

use of org.apache.poi.hssf.record.ColumnInfoRecord in project poi by apache.

the class TestColumnInfoRecordsAggregate method confirmCIR.

private static void confirmCIR(ColumnInfoRecord[] cirs, int ix, int startColIx, int endColIx, int level, boolean isHidden, boolean isCollapsed) {
    ColumnInfoRecord cir = cirs[ix];
    assertEquals("startColIx", startColIx, cir.getFirstColumn());
    assertEquals("endColIx", endColIx, cir.getLastColumn());
    assertEquals("level", level, cir.getOutlineLevel());
    assertEquals("hidden", isHidden, cir.getHidden());
    assertEquals("collapsed", isCollapsed, cir.getCollapsed());
}
Also used : ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord)

Example 14 with ColumnInfoRecord

use of org.apache.poi.hssf.record.ColumnInfoRecord in project poi by apache.

the class ColumnInfoRecordsAggregate method setColumn.

public void setColumn(int targetColumnIx, Short xfIndex, Integer width, Integer level, Boolean hidden, Boolean collapsed) {
    ColumnInfoRecord ci = null;
    int k = 0;
    for (k = 0; k < records.size(); k++) {
        ColumnInfoRecord tci = records.get(k);
        if (tci.containsColumn(targetColumnIx)) {
            ci = tci;
            break;
        }
        if (tci.getFirstColumn() > targetColumnIx) {
            // exit now so k will be the correct insert pos
            break;
        }
    }
    if (ci == null) {
        // okay so there ISN'T a column info record that covers this column so lets create one!
        ColumnInfoRecord nci = new ColumnInfoRecord();
        nci.setFirstColumn(targetColumnIx);
        nci.setLastColumn(targetColumnIx);
        setColumnInfoFields(nci, xfIndex, width, level, hidden, collapsed);
        insertColumn(k, nci);
        attemptMergeColInfoRecords(k);
        return;
    }
    boolean styleChanged = xfIndex != null && ci.getXFIndex() != xfIndex.shortValue();
    boolean widthChanged = width != null && ci.getColumnWidth() != width.shortValue();
    boolean levelChanged = level != null && ci.getOutlineLevel() != level.intValue();
    boolean hiddenChanged = hidden != null && ci.getHidden() != hidden.booleanValue();
    boolean collapsedChanged = collapsed != null && ci.getCollapsed() != collapsed.booleanValue();
    boolean columnChanged = styleChanged || widthChanged || levelChanged || hiddenChanged || collapsedChanged;
    if (!columnChanged) {
        // do nothing...nothing changed.
        return;
    }
    if (ci.getFirstColumn() == targetColumnIx && ci.getLastColumn() == targetColumnIx) {
        // ColumnInfo ci for a single column, the target column
        setColumnInfoFields(ci, xfIndex, width, level, hidden, collapsed);
        attemptMergeColInfoRecords(k);
        return;
    }
    if (ci.getFirstColumn() == targetColumnIx || ci.getLastColumn() == targetColumnIx) {
        // we'll just divide the info and create a new one
        if (ci.getFirstColumn() == targetColumnIx) {
            ci.setFirstColumn(targetColumnIx + 1);
        } else {
            ci.setLastColumn(targetColumnIx - 1);
            // adjust insert pos to insert after
            k++;
        }
        ColumnInfoRecord nci = copyColInfo(ci);
        nci.setFirstColumn(targetColumnIx);
        nci.setLastColumn(targetColumnIx);
        setColumnInfoFields(nci, xfIndex, width, level, hidden, collapsed);
        insertColumn(k, nci);
        attemptMergeColInfoRecords(k);
    } else {
        //split to 3 records
        ColumnInfoRecord ciStart = ci;
        ColumnInfoRecord ciMid = copyColInfo(ci);
        ColumnInfoRecord ciEnd = copyColInfo(ci);
        int lastcolumn = ci.getLastColumn();
        ciStart.setLastColumn(targetColumnIx - 1);
        ciMid.setFirstColumn(targetColumnIx);
        ciMid.setLastColumn(targetColumnIx);
        setColumnInfoFields(ciMid, xfIndex, width, level, hidden, collapsed);
        insertColumn(++k, ciMid);
        ciEnd.setFirstColumn(targetColumnIx + 1);
        ciEnd.setLastColumn(lastcolumn);
        insertColumn(++k, ciEnd);
    // no need to attemptMergeColInfoRecords because we
    // know both on each side are different
    }
}
Also used : ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord)

Example 15 with ColumnInfoRecord

use of org.apache.poi.hssf.record.ColumnInfoRecord in project poi by apache.

the class ColumnInfoRecordsAggregate method collapseColumn.

public void collapseColumn(int columnIndex) {
    int colInfoIx = findColInfoIdx(columnIndex, 0);
    if (colInfoIx == -1) {
        return;
    }
    // Find the start of the group.
    int groupStartColInfoIx = findStartOfColumnOutlineGroup(colInfoIx);
    ColumnInfoRecord columnInfo = getColInfo(groupStartColInfoIx);
    // Hide all the columns until the end of the group
    int lastColIx = setGroupHidden(groupStartColInfoIx, columnInfo.getOutlineLevel(), true);
    // Write collapse field
    setColumn(lastColIx + 1, null, null, null, null, Boolean.TRUE);
}
Also used : ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord)

Aggregations

ColumnInfoRecord (org.apache.poi.hssf.record.ColumnInfoRecord)16 Test (org.junit.Test)2 AssertionFailedError (junit.framework.AssertionFailedError)1