Search in sources :

Example 16 with ColumnInfoRecord

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

the class TestSheet method testXFIndexForColumn.

/**
	 * test newly added method Sheet.getXFIndexForColAt(..)
	 * works as designed.
	 */
@Test
public void testXFIndexForColumn() {
    final short TEST_IDX = 10;
    // 15
    final short DEFAULT_IDX = 0xF;
    short xfindex = Short.MIN_VALUE;
    InternalSheet sheet = InternalSheet.createSheet();
    // without ColumnInfoRecord
    xfindex = sheet.getXFIndexForColAt((short) 0);
    assertEquals(DEFAULT_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 1);
    assertEquals(DEFAULT_IDX, xfindex);
    ColumnInfoRecord nci = new ColumnInfoRecord();
    sheet._columnInfos.insertColumn(nci);
    // single column ColumnInfoRecord
    nci.setFirstColumn((short) 2);
    nci.setLastColumn((short) 2);
    nci.setXFIndex(TEST_IDX);
    xfindex = sheet.getXFIndexForColAt((short) 0);
    assertEquals(DEFAULT_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 1);
    assertEquals(DEFAULT_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 2);
    assertEquals(TEST_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 3);
    assertEquals(DEFAULT_IDX, xfindex);
    // ten column ColumnInfoRecord
    nci.setFirstColumn((short) 2);
    nci.setLastColumn((short) 11);
    nci.setXFIndex(TEST_IDX);
    xfindex = sheet.getXFIndexForColAt((short) 1);
    assertEquals(DEFAULT_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 2);
    assertEquals(TEST_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 6);
    assertEquals(TEST_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 11);
    assertEquals(TEST_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 12);
    assertEquals(DEFAULT_IDX, xfindex);
    // single column ColumnInfoRecord starting at index 0
    nci.setFirstColumn((short) 0);
    nci.setLastColumn((short) 0);
    nci.setXFIndex(TEST_IDX);
    xfindex = sheet.getXFIndexForColAt((short) 0);
    assertEquals(TEST_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 1);
    assertEquals(DEFAULT_IDX, xfindex);
    // ten column ColumnInfoRecord starting at index 0
    nci.setFirstColumn((short) 0);
    nci.setLastColumn((short) 9);
    nci.setXFIndex(TEST_IDX);
    xfindex = sheet.getXFIndexForColAt((short) 0);
    assertEquals(TEST_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 7);
    assertEquals(TEST_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 9);
    assertEquals(TEST_IDX, xfindex);
    xfindex = sheet.getXFIndexForColAt((short) 10);
    assertEquals(DEFAULT_IDX, xfindex);
}
Also used : ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord) Test(org.junit.Test)

Aggregations

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