use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty in project poi by apache.
the class XSSFFont method setCharSet.
/**
* set character-set to use.
*
* @param charSet
*/
public void setCharSet(FontCharset charSet) {
CTIntProperty charsetProperty;
if (_ctFont.sizeOfCharsetArray() == 0) {
charsetProperty = _ctFont.addNewCharset();
} else {
charsetProperty = _ctFont.getCharsetArray(0);
}
// We know that FontCharset only has valid entries in it,
// so we can just set the int value from it
charsetProperty.setVal(charSet.getValue());
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty 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();
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty 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());
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty in project poi by apache.
the class XSSFFont method getCharSet.
/**
* get character-set to use.
*
* @return int - character-set (0-255)
* @see org.apache.poi.ss.usermodel.FontCharset
*/
public int getCharSet() {
CTIntProperty charset = _ctFont.sizeOfCharsetArray() == 0 ? null : _ctFont.getCharsetArray(0);
int val = charset == null ? FontCharset.ANSI.getValue() : FontCharset.valueOf(charset.getVal()).getValue();
return val;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty in project poi by apache.
the class XSSFFont method setFamily.
/**
* Set the font family this font belongs to.
* A font family is a set of fonts having common stroke width and serif characteristics.
* The font name overrides when there are conflicting values.
*
* @param value - font family
* @see FontFamily
*/
public void setFamily(int value) {
CTIntProperty family = _ctFont.sizeOfFamilyArray() == 0 ? _ctFont.addNewFamily() : _ctFont.getFamilyArray(0);
family.setVal(value);
}
Aggregations