Search in sources :

Example 6 with ColumnInfoRecord

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

the class ColumnInfoRecordsAggregate method attemptMergeColInfoRecords.

/**
	 * Attempts to merge the col info record at the specified index
	 * with either or both of its neighbours
	 */
private void attemptMergeColInfoRecords(int colInfoIx) {
    int nRecords = records.size();
    if (colInfoIx < 0 || colInfoIx >= nRecords) {
        throw new IllegalArgumentException("colInfoIx " + colInfoIx + " is out of range (0.." + (nRecords - 1) + ")");
    }
    ColumnInfoRecord currentCol = getColInfo(colInfoIx);
    int nextIx = colInfoIx + 1;
    if (nextIx < nRecords) {
        if (mergeColInfoRecords(currentCol, getColInfo(nextIx))) {
            records.remove(nextIx);
        }
    }
    if (colInfoIx > 0) {
        if (mergeColInfoRecords(getColInfo(colInfoIx - 1), currentCol)) {
            records.remove(colInfoIx);
        }
    }
}
Also used : ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord)

Example 7 with ColumnInfoRecord

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

the class ColumnInfoRecordsAggregate method findStartOfColumnOutlineGroup.

private int findStartOfColumnOutlineGroup(int pIdx) {
    // Find the start of the group.
    ColumnInfoRecord columnInfo = records.get(pIdx);
    int level = columnInfo.getOutlineLevel();
    int idx = pIdx;
    while (idx != 0) {
        ColumnInfoRecord prevColumnInfo = records.get(idx - 1);
        if (!prevColumnInfo.isAdjacentBefore(columnInfo)) {
            break;
        }
        if (prevColumnInfo.getOutlineLevel() < level) {
            break;
        }
        idx--;
        columnInfo = prevColumnInfo;
    }
    return idx;
}
Also used : ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord)

Example 8 with ColumnInfoRecord

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

the class ColumnInfoRecordsAggregate method setGroupHidden.

/**
	 * Sets all adjacent columns of the same outline level to the specified hidden status.
	 * @param pIdx the col info index of the start of the outline group
	 * @return the column index of the last column in the outline group
	 */
private int setGroupHidden(int pIdx, int level, boolean hidden) {
    int idx = pIdx;
    ColumnInfoRecord columnInfo = getColInfo(idx);
    while (idx < records.size()) {
        columnInfo.setHidden(hidden);
        if (idx + 1 < records.size()) {
            ColumnInfoRecord nextColumnInfo = getColInfo(idx + 1);
            if (!columnInfo.isAdjacentBefore(nextColumnInfo)) {
                break;
            }
            if (nextColumnInfo.getOutlineLevel() < level) {
                break;
            }
            columnInfo = nextColumnInfo;
        }
        idx++;
    }
    return columnInfo.getLastColumn();
}
Also used : ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord)

Example 9 with ColumnInfoRecord

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

the class ColumnInfoRecordsAggregate method expandColumn.

public void expandColumn(int columnIndex) {
    int idx = findColInfoIdx(columnIndex, 0);
    if (idx == -1) {
        return;
    }
    // If it is already expanded do nothing.
    if (!isColumnGroupCollapsed(idx)) {
        return;
    }
    // Find the start/end of the group.
    int startIdx = findStartOfColumnOutlineGroup(idx);
    int endIdx = findEndOfColumnOutlineGroup(idx);
    // expand:
    // colapsed bit must be unset
    // hidden bit gets unset _if_ surrounding groups are expanded you can determine
    //   this by looking at the hidden bit of the enclosing group.  You will have
    //   to look at the start and the end of the current group to determine which
    //   is the enclosing group
    // hidden bit only is altered for this outline level.  ie.  don't uncollapse contained groups
    ColumnInfoRecord columnInfo = getColInfo(endIdx);
    if (!isColumnGroupHiddenByParent(idx)) {
        int outlineLevel = columnInfo.getOutlineLevel();
        for (int i = startIdx; i <= endIdx; i++) {
            ColumnInfoRecord ci = getColInfo(i);
            if (outlineLevel == ci.getOutlineLevel())
                ci.setHidden(false);
        }
    }
    // Write collapse flag (stored in a single col info record after this outline group)
    setColumn(columnInfo.getLastColumn() + 1, null, null, null, null, Boolean.FALSE);
}
Also used : ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord)

Example 10 with ColumnInfoRecord

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

the class TestSheetAdditional method testGetCellWidth.

public void testGetCellWidth() {
    InternalSheet sheet = InternalSheet.createSheet();
    ColumnInfoRecord nci = new ColumnInfoRecord();
    // Prepare test model
    nci.setFirstColumn(5);
    nci.setLastColumn(10);
    nci.setColumnWidth(100);
    sheet._columnInfos.insertColumn(nci);
    assertEquals(100, sheet.getColumnWidth(5));
    assertEquals(100, sheet.getColumnWidth(6));
    assertEquals(100, sheet.getColumnWidth(7));
    assertEquals(100, sheet.getColumnWidth(8));
    assertEquals(100, sheet.getColumnWidth(9));
    assertEquals(100, sheet.getColumnWidth(10));
    sheet.setColumnWidth(6, 200);
    assertEquals(100, sheet.getColumnWidth(5));
    assertEquals(200, sheet.getColumnWidth(6));
    assertEquals(100, sheet.getColumnWidth(7));
    assertEquals(100, sheet.getColumnWidth(8));
    assertEquals(100, sheet.getColumnWidth(9));
    assertEquals(100, sheet.getColumnWidth(10));
}
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