Bug 50258 - XSSFRichTextString corrupts Excel file when applyFont() is used
Summary: XSSFRichTextString corrupts Excel file when applyFont() is used
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.7-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-11 17:53 UTC by JaBoGo
Modified: 2010-11-18 15:08 UTC (History)
0 users



Attachments
Corrupted Rich Text XLSX (3.30 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2010-11-11 17:53 UTC, JaBoGo
Details
Corrupted file (generated by POI) (3.32 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2010-11-12 11:50 UTC, JaBoGo
Details
Valid file (generated by Excel 2010) (9.57 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2010-11-12 11:51 UTC, JaBoGo
Details

Note You need to log in before you can comment on or make changes to this bug.
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