<changes>
<release version="3.7-SNAPSHOT" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">49273 - Correct handling for Font Character Sets with indicies greater than 127</action>
<action dev="POI-DEVELOPERS" type="add">49334 - Track the ValueRangeRecords of charts in HSSFChart, to allow the basic axis operations</action>
<action dev="POI-DEVELOPERS" type="add">49242 - Track the LinkDataRecords of charts in HSSFChart</action>
<action dev="POI-DEVELOPERS" type="add">Improved performance of XSSFWorkbook.write </action>
* @see #DEFAULT_CHARSET
* @see #SYMBOL_CHARSET
*/
- public byte getCharSet()
+ public int getCharSet()
{
- return font.getCharset();
+ byte charset = font.getCharset();
+ if(charset >= 0) {
+ return (int)charset;
+ } else {
+ return charset + 256;
+ }
+ }
+
+ /**
+ * set character-set to use.
+ * @see #ANSI_CHARSET
+ * @see #DEFAULT_CHARSET
+ * @see #SYMBOL_CHARSET
+ */
+ public void setCharSet(int charset)
+ {
+ byte cs = (byte)charset;
+ if(charset > 127) {
+ cs = (byte)(charset-256);
+ }
+ setCharSet(cs);
}
/**
* @see #DEFAULT_CHARSET
* @see #SYMBOL_CHARSET
*/
- byte getCharSet();
+ int getCharSet();
/**
* set character-set to use.
* @see #SYMBOL_CHARSET
*/
void setCharSet(byte charset);
+ /**
+ * set character-set to use.
+ * @see #ANSI_CHARSET
+ * @see #DEFAULT_CHARSET
+ * @see #SYMBOL_CHARSET
+ */
+ void setCharSet(int charset);
/**
* get the index within the XSSFWorkbook (sequence within the collection of Font objects)
/**
* get character-set to use.
*
- * @return byte - character-set
+ * @return int - character-set (0-255)
* @see org.apache.poi.ss.usermodel.FontCharset
*/
- public byte getCharSet() {
+ 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 (byte)val;
+ return val;
}
* @see FontCharset
*/
public void setCharSet(byte charset) {
+ int cs = (int)charset;
+ if(cs < 0) {
+ cs += 256;
+ }
+ setCharSet(cs);
+ }
+ /**
+ * set character-set to use.
+ *
+ * @param charset - charset
+ * @see FontCharset
+ */
+ public void setCharSet(int charset) {
CTIntProperty charsetProperty = _ctFont.sizeOfCharsetArray() == 0 ? _ctFont.addNewCharset() : _ctFont.getCharsetArray(0);
switch (charset) {
case Font.ANSI_CHARSET:
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.xssf.XSSFTestDataSamples;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
xssfFont.setCharSet(FontCharset.DEFAULT);
assertEquals(FontCharset.DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
+
+
+ // Now try with a few sample files
+
+ // Normal charset
+ XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
+ assertEquals(0,
+ workbook.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
+ );
+
+ // GB2312 charact set
+ workbook = XSSFTestDataSamples.openSampleWorkbook("49273.xlsx");
+ assertEquals(134,
+ workbook.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
+ );
}
public void testFontName() {