execute the code: Workbook workbook = new XSSFWorkbook(); Sheet createSheet = workbook.createSheet(); Row row = createSheet.createRow(0); Cell cell = row.createCell(0); CellStyle cellStyle = workbook.createCellStyle(); Font createFont = workbook.createFont(); createFont.setBoldweight((short)300); cellStyle.setFont(createFont); cell.setCellStyle(cellStyle); short fontIndex = cell.getCellStyle().getFontIndex(); Font fontAt = workbook.getFontAt(fontIndex); System.out.println(fontAt.getBoldweight()); the boldweight can't be set to 300. due to : public short getBoldweight() { return getBold() ? BOLDWEIGHT_BOLD : BOLDWEIGHT_NORMAL; } org.apache.poi.xssf.usermodel.XSSFFont.getBoldweight() is 400 or 700 only. if so, why provide the setBoldweight() to set any short value?
at the sometime, HSSFFont's set/get boldweight is right,
Looking at XSSFFont.setBoldweight(short boldweight), it looks like getBoldweight and setBoldweight were never intended to be used with literals--only the Font.BOLDWEIGHT_NORMAL and Font.BOLDWEIGHT_BOLD constants. [1] Your example can be simplified to: Workbook wb = new XSSFWorkbook(); Font font = wb.createFont(); short weight = 314; assumeTrue(weight != Font.BOLDWEIGHT_NORMAL); assumeTrue(weight != Font.BOLDWEIGHT_BOLD); font.setBoldweight(weight); assertEquals(weight, font.getBoldweight); The XSSFFont never stores the requested boldweight. If the OOXML format allows specifying a numeric weight in addition to a boolean bold/not-bold value, then this is a bug in POI. From what I can make out in the 2006 OOXML schema, custom font weights are not part of the standard. sml-styles.xsd: <xsd:complexType name="CT_Font"> <xsd:choice maxOccurs="unbounded"> ... <xsd:element name="b" type="CT_BooleanProperty" minOccurs="0" maxOccurs="1"> <xsd:annotation> <xsd:documentation>Bold</xsd:documentation> </xsd:annotation> </xsd:element> ... </xsd:choice> </xsd:complexType> A note should be added to XSSFFont.get/setBoldweight javadocs that only the named constants will work. [1] https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java?revision=1701134&view=markup#l300
Created attachment 33730 [details] Javadocs fixes for XSSFFont
Or deprecate setBoldweight.
Are there any real usecases for using get/setBoldweight(short) when get/setBold(boolean) exists? I don't think Excel OOXML schema supports non-boolean bold values. Are there any objections to deprecating get/setBoldweight?
Applied deprecation warning in r1748658.