Search in sources :

Example 6 with FontRecord

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

the class HSSFCellStyle method cloneStyleFrom.

public void cloneStyleFrom(HSSFCellStyle source) {
    // First we need to clone the extended format
    //  record
    _format.cloneStyleFrom(source._format);
    // Handle matching things if we cross workbooks
    if (_workbook != source._workbook) {
        lastDateFormat.set(Short.MIN_VALUE);
        lastFormats.set(null);
        getDataFormatStringCache.set(null);
        // Then we need to clone the format string,
        //  and update the format record for this
        short fmt = (short) _workbook.createFormat(source.getDataFormatString());
        setDataFormat(fmt);
        // Finally we need to clone the font,
        //  and update the format record for this
        FontRecord fr = _workbook.createNewFont();
        fr.cloneStyleFrom(source._workbook.getFontRecordAt(source.getFontIndex()));
        HSSFFont font = new HSSFFont((short) _workbook.getFontIndex(fr), fr);
        setFont(font);
    }
}
Also used : FontRecord(org.apache.poi.hssf.record.FontRecord)

Example 7 with FontRecord

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

the class TestWorkbook method testFontStuff.

@Test
public void testFontStuff() throws IOException {
    HSSFWorkbook hwb = new HSSFWorkbook();
    InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(hwb);
    assertEquals(4, wb.getNumberOfFontRecords());
    assertEquals(68, wb.getRecords().size());
    FontRecord f1 = wb.getFontRecordAt(0);
    FontRecord f4 = wb.getFontRecordAt(3);
    assertEquals(0, wb.getFontIndex(f1));
    assertEquals(3, wb.getFontIndex(f4));
    assertEquals(f1, wb.getFontRecordAt(0));
    assertEquals(f4, wb.getFontRecordAt(3));
    // There is no 4! new ones go in at 5
    FontRecord n = wb.createNewFont();
    assertEquals(69, wb.getRecords().size());
    assertEquals(5, wb.getNumberOfFontRecords());
    assertEquals(5, wb.getFontIndex(n));
    assertEquals(n, wb.getFontRecordAt(5));
    // And another
    FontRecord n6 = wb.createNewFont();
    assertEquals(70, wb.getRecords().size());
    assertEquals(6, wb.getNumberOfFontRecords());
    assertEquals(6, wb.getFontIndex(n6));
    assertEquals(n6, wb.getFontRecordAt(6));
    // Now remove the one formerly at 5
    assertEquals(70, wb.getRecords().size());
    wb.removeFontRecord(n);
    // Check that 6 has gone to 5
    assertEquals(69, wb.getRecords().size());
    assertEquals(5, wb.getNumberOfFontRecords());
    assertEquals(5, wb.getFontIndex(n6));
    assertEquals(n6, wb.getFontRecordAt(5));
    // Check that the earlier ones are unchanged
    assertEquals(0, wb.getFontIndex(f1));
    assertEquals(3, wb.getFontIndex(f4));
    assertEquals(f1, wb.getFontRecordAt(0));
    assertEquals(f4, wb.getFontRecordAt(3));
    // Finally, add another one
    FontRecord n7 = wb.createNewFont();
    assertEquals(70, wb.getRecords().size());
    assertEquals(6, wb.getNumberOfFontRecords());
    assertEquals(6, wb.getFontIndex(n7));
    assertEquals(n7, wb.getFontRecordAt(6));
    hwb.close();
}
Also used : FontRecord(org.apache.poi.hssf.record.FontRecord) TestHSSFWorkbook(org.apache.poi.hssf.usermodel.TestHSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

FontRecord (org.apache.poi.hssf.record.FontRecord)7 HashSet (java.util.HashSet)1 ExtendedFormatRecord (org.apache.poi.hssf.record.ExtendedFormatRecord)1 UnicodeString (org.apache.poi.hssf.record.common.UnicodeString)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 TestHSSFWorkbook (org.apache.poi.hssf.usermodel.TestHSSFWorkbook)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 Test (org.junit.Test)1