Bug 50258

Summary: XSSFRichTextString corrupts Excel file when applyFont() is used
Product: POI Reporter: JaBoGo <bugzilla>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: 3.7-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Corrupted Rich Text XLSX
Corrupted file (generated by POI)
Valid file (generated by Excel 2010)

Description JaBoGo 2010-11-11 17:53:43 UTC
Created attachment 26284 [details]
Corrupted Rich Text XLSX

Excel complains that the file created by the followin example is corrupted. Two fonts are applied to the string "plain bold italic plain" and the space before "bold" is removed. If you strip of the last five chars (" plain"), the file opens without a warning but the space between "plain" and "bold" is still missing.

The errors make the font aplying unusable for XSSF. The same test case with HSSF works fine.

----------

import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class PoiRichTextBug
{
  public static void main(String[] args) throws Exception
  {
    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet();
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    RichTextString text = workbook.getCreationHelper().createRichTextString("plain bold italic plain");
    Font font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    text.applyFont(6, 10, font);
    font = workbook.createFont();
    font.setItalic(true);
    text.applyFont(11, 17, font);
    cell.setCellValue(text);
    workbook.write(new FileOutputStream("RichText.xlsx"));
  }
}
Comment 1 Nick Burch 2010-11-12 06:02:28 UTC
Could you please create the same document using excel? We can then compare the XML generated by POI, and the XML generated by excel, and hopefully spot what POI is doing wrong in your case.
Comment 2 JaBoGo 2010-11-12 11:50:01 UTC
Created attachment 26291 [details]
Corrupted file (generated by POI)
Comment 3 JaBoGo 2010-11-12 11:51:01 UTC
Created attachment 26292 [details]
Valid file (generated by Excel 2010)
Comment 4 JaBoGo 2010-11-12 11:52:39 UTC
(In reply to comment #1)
> Could you please create the same document using excel? We can then compare the
> XML generated by POI, and the XML generated by excel, and hopefully spot what
> POI is doing wrong in your case.

The two new attachments describe the test case. Hope this helps.
Comment 5 Yegor Kozlov 2010-11-18 15:08:52 UTC
Fixed in r1036599

Yegor