Search in sources :

Example 6 with CTFont

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont in project poi by apache.

the class TestXSSFBugs method saveAndReloadReport.

private void saveAndReloadReport(Workbook wb, File outFile) throws IOException {
    // run some method on the font to verify if it is "disconnected" already
    //for(short i = 0;i < 256;i++)
    {
        Font font = wb.getFontAt((short) 0);
        if (font instanceof XSSFFont) {
            XSSFFont xfont = (XSSFFont) wb.getFontAt((short) 0);
            CTFontImpl ctFont = (CTFontImpl) xfont.getCTFont();
            assertEquals(0, ctFont.sizeOfBArray());
        }
    }
    FileOutputStream fileOutStream = new FileOutputStream(outFile);
    try {
        wb.write(fileOutStream);
    } finally {
        fileOutStream.close();
    }
    FileInputStream is = new FileInputStream(outFile);
    try {
        Workbook newWB = null;
        try {
            if (wb instanceof XSSFWorkbook) {
                newWB = new XSSFWorkbook(is);
            } else if (wb instanceof HSSFWorkbook) {
                newWB = new HSSFWorkbook(is);
            } else if (wb instanceof SXSSFWorkbook) {
                newWB = new SXSSFWorkbook(new XSSFWorkbook(is));
            } else {
                throw new IllegalStateException("Unknown workbook: " + wb);
            }
            assertNotNull(newWB.getSheet("test"));
        } finally {
            if (newWB != null) {
                newWB.close();
            }
        }
    } finally {
        is.close();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CTFontImpl(org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl) FileInputStream(java.io.FileInputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 7 with CTFont

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont in project poi by apache.

the class TestXSSFFont method testFamily.

@Test
public void testFamily() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTIntProperty family = ctFont.addNewFamily();
    family.setVal(FontFamily.MODERN.getValue());
    ctFont.setFamilyArray(0, family);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals(FontFamily.MODERN.getValue(), xssfFont.getFamily());
}
Also used : CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) CTIntProperty(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty) Test(org.junit.Test)

Example 8 with CTFont

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont in project poi by apache.

the class TestXSSFFont method testFontHeight.

@Test
public void testFontHeight() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTFontSize size = ctFont.addNewSz();
    size.setVal(11);
    ctFont.setSzArray(0, size);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals(11, xssfFont.getFontHeightInPoints());
    xssfFont.setFontHeight(20);
    assertEquals(20.0, ctFont.getSzArray(0).getVal(), 0.0);
}
Also used : CTFontSize(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize) CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) Test(org.junit.Test)

Example 9 with CTFont

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont in project poi by apache.

the class TestXSSFFont method testThemeColor.

@Test
public void testThemeColor() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTColor color = ctFont.addNewColor();
    color.setTheme(1);
    ctFont.setColorArray(0, color);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals(ctFont.getColorArray(0).getTheme(), xssfFont.getThemeColor());
    xssfFont.setThemeColor(IndexedColors.RED.getIndex());
    assertEquals(IndexedColors.RED.getIndex(), ctFont.getColorArray(0).getTheme());
}
Also used : CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor) Test(org.junit.Test)

Example 10 with CTFont

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont in project poi by apache.

the class TestXSSFFont method testBold.

@Test
public void testBold() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTBooleanProperty bool = ctFont.addNewB();
    bool.setVal(false);
    ctFont.setBArray(0, bool);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals(false, xssfFont.getBold());
    xssfFont.setBold(true);
    assertEquals(ctFont.sizeOfBArray(), 1);
    assertEquals(true, ctFont.getBArray(0).getVal());
}
Also used : CTBooleanProperty(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty) CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) Test(org.junit.Test)

Aggregations

CTFont (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont)16 Test (org.junit.Test)14 CTColor (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)5 CTBooleanProperty (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty)3 POIXMLException (org.apache.poi.POIXMLException)2 CTFontSize (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize)2 CTIntProperty (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 XmlException (org.apache.xmlbeans.XmlException)1 CTBorder (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder)1 CTFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill)1 CTFontName (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName)1 CTFontScheme (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme)1 CTUnderlineProperty (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty)1 CTVerticalAlignFontProperty (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty)1 CTFontImpl (org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl)1