Bug 55385

Summary: XSSFFont.setBoldweight(short) to 300 but getBoldweight return 400
Product: POI Reporter: fujian <fujian1115>
Component: XSSFAssignee: POI Developers List <dev>
Severity: major    
Priority: P2    
Version: 3.10-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Bug Depends on:    
Bug Blocks: 59718    
Attachments: Javadocs fixes for XSSFFont

Description fujian 2013-08-08 01:06:07 UTC
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();


		short fontIndex = cell.getCellStyle().getFontIndex();
		Font fontAt = workbook.getFontAt(fontIndex);

the boldweight can't be set to 300. due to :

    public short getBoldweight()
        return getBold() ? BOLDWEIGHT_BOLD : BOLDWEIGHT_NORMAL;

is 400 or 700 only. if so, why provide the setBoldweight() to set any short value?
Comment 1 fujian 2013-08-08 01:07:28 UTC
at the sometime, HSSFFont's set/get boldweight is right,
Comment 2 Javen O'Neal 2016-04-06 02:48:00 UTC
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);
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.

  <xsd:complexType name="CT_Font">
    <xsd:choice maxOccurs="unbounded">
      <xsd:element name="b" type="CT_BooleanProperty" minOccurs="0" maxOccurs="1">

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
Comment 3 Javen O'Neal 2016-04-06 03:27:51 UTC
Created attachment 33730 [details]
Javadocs fixes for XSSFFont
Comment 4 Javen O'Neal 2016-06-15 10:53:13 UTC
Or deprecate setBoldweight.
Comment 5 Javen O'Neal 2016-06-16 06:18:10 UTC
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?
Comment 6 Javen O'Neal 2016-06-16 06:53:05 UTC
Applied deprecation warning in r1748658.