poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 43091] New: - Applying a font to a HSSFRichTextString can lead to that the file can't be loaded by Excel any more
Date Sat, 11 Aug 2007 13:33:53 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43091>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43091

           Summary: Applying a font to a HSSFRichTextString can lead to that
                    the file can't be loaded by Excel any more
           Product: POI
           Version: 3.0
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: major
          Priority: P2
         Component: HSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: jan.dostert@sap.com


Hi,

applying a font to a HSSFRichTextString with poi-3.0.1-FINAL-20070705.jar can
lead to that the file can't be loaded by Excel any more (I tried Excel 2003 and
Excel 2007).

There are no problems in saving the file. However, when opening the file with
Excel, I get the error message "Excel found unreadable content in foo.xls".

Attached a small test case  and some sample data which reproduce the problem.
The created excel file works fine if the font is not applied to the text in row
2775. But if the font is applied to the text in row 2775, the excel file can't
be loaded any more.
There is nothing special about the particular String in row 2775. When applying
the font to this String only, the excel file can be loaded as well. It's just in
this scenario, when applying the fonts to line 1 - 2774, the excel file can be
loaded. But when applying the fonts to line 1 - 2775, the excel file can't be
loaded any more.  

Actually this problem occurs all the time when I export a big table. As a
workaround, I do not apply fonts at all. 

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class ApplyFont {

    public static void main(String args[]) throws Exception {

        HSSFWorkbook workBook = new HSSFWorkbook();
        HSSFSheet sheet = workBook.createSheet();
        HSSFFont font = workBook.createFont();
       
        BufferedReader br = new BufferedReader(new FileReader("testdata.txt"));
        
        String line;
        short currentRow = 0;
        
        while ( (line = br.readLine()) != null) {
            HSSFRow row = sheet.createRow(currentRow++);
            HSSFCell cell = row.createCell((short)0);
                
            HSSFRichTextString text = new HSSFRichTextString(line); 
            
            // if we don't apply the font to this particular line,
            // everything works fine 
            // if (currentRow != 2775) {
                text.applyFont(0, line.length(), font);
            // }
            
            cell.setCellValue(text);
        }
        
        workBook.write(new FileOutputStream("foo.xls"));
    }
}

Regards,
Jan

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message