Search in sources :

Example 1 with CTFont

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

the class TestXSSFFont method testUnderline.

@Test
public void testUnderline() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTUnderlineProperty underlinePropr = ctFont.addNewU();
    underlinePropr.setVal(STUnderlineValues.SINGLE);
    ctFont.setUArray(0, underlinePropr);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals(Font.U_SINGLE, xssfFont.getUnderline());
    xssfFont.setUnderline(Font.U_DOUBLE);
    assertEquals(ctFont.sizeOfUArray(), 1);
    assertEquals(STUnderlineValues.DOUBLE, ctFont.getUArray(0).getVal());
    xssfFont.setUnderline(FontUnderline.DOUBLE_ACCOUNTING);
    assertEquals(ctFont.sizeOfUArray(), 1);
    assertEquals(STUnderlineValues.DOUBLE_ACCOUNTING, ctFont.getUArray(0).getVal());
}
Also used : CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) CTUnderlineProperty(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty) Test(org.junit.Test)

Example 2 with CTFont

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

the class TestXSSFFont method testScheme.

@Test
public void testScheme() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTFontScheme scheme = ctFont.addNewScheme();
    scheme.setVal(STFontScheme.MAJOR);
    ctFont.setSchemeArray(0, scheme);
    XSSFFont font = new XSSFFont(ctFont);
    assertEquals(FontScheme.MAJOR, font.getScheme());
    font.setScheme(FontScheme.NONE);
    assertEquals(STFontScheme.NONE, ctFont.getSchemeArray(0).getVal());
}
Also used : CTFontScheme(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme) CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) Test(org.junit.Test)

Example 3 with CTFont

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

the class TestXSSFFont method testFontName.

@Test
public void testFontName() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTFontName fname = ctFont.addNewName();
    fname.setVal("Arial");
    ctFont.setNameArray(0, fname);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals("Arial", xssfFont.getFontName());
    xssfFont.setFontName("Courier");
    assertEquals("Courier", ctFont.getNameArray(0).getVal());
}
Also used : CTFontName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName) CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) Test(org.junit.Test)

Example 4 with CTFont

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

the class TestXSSFFont method testItalic.

@Test
public void testItalic() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTBooleanProperty bool = ctFont.addNewI();
    bool.setVal(false);
    ctFont.setIArray(0, bool);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals(false, xssfFont.getItalic());
    xssfFont.setItalic(true);
    assertEquals(ctFont.sizeOfIArray(), 1);
    assertEquals(true, ctFont.getIArray(0).getVal());
    assertEquals(true, ctFont.getIArray(0).getVal());
}
Also used : CTBooleanProperty(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty) CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) Test(org.junit.Test)

Example 5 with CTFont

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

the class TestXSSFFont method testCharSet.

@Test
public void testCharSet() throws IOException {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTIntProperty prop = ctFont.addNewCharset();
    prop.setVal(FontCharset.ANSI.getValue());
    ctFont.setCharsetArray(0, prop);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals(Font.ANSI_CHARSET, xssfFont.getCharSet());
    xssfFont.setCharSet(FontCharset.DEFAULT);
    assertEquals(FontCharset.DEFAULT.getValue(), ctFont.getCharsetArray(0).getVal());
    // Try with a few less usual ones:
    // Set with the Charset itself
    xssfFont.setCharSet(FontCharset.RUSSIAN);
    assertEquals(FontCharset.RUSSIAN.getValue(), xssfFont.getCharSet());
    // And set with the Charset index
    xssfFont.setCharSet(FontCharset.ARABIC.getValue());
    assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
    xssfFont.setCharSet((byte) (FontCharset.ARABIC.getValue()));
    assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
    // This one isn't allowed
    assertEquals(null, FontCharset.valueOf(9999));
    try {
        xssfFont.setCharSet(9999);
        fail("Shouldn't be able to set an invalid charset");
    } catch (POIXMLException e) {
    }
    // Now try with a few sample files
    // Normal charset
    XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
    assertEquals(0, wb1.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet());
    wb1.close();
    // GB2312 charact set
    XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("49273.xlsx");
    assertEquals(134, wb2.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet());
    wb2.close();
}
Also used : CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) CTIntProperty(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty) POIXMLException(org.apache.poi.POIXMLException) 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