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 40520] New: - HSSFFont.applyFont() formats wrong parts of HSSFRichTextString
Date Fri, 15 Sep 2006 13:22:43 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=40520>.
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=40520

           Summary: HSSFFont.applyFont() formats wrong parts of
                    HSSFRichTextString
           Product: POI
           Version: 3.0-dev
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
        AssignedTo: poi-dev@jakarta.apache.org
        ReportedBy: Martin.Jost@siemens.com


I'm using poi-bin-3.0-alpha2-20060616 because I need support for (RichText) 
formatting within a cell. The resulting sheet is read by Excel 2003 SP2.

I found a number of cases where I think, HSSFFont.applyFont() formats wrong 
parts of HSSFRichTextString. (see testcase below)

This seems to happen in (at least) the following cases:
    // overlapped range => will format whole String
    str.applyFont(0,7,font);
    str.applyFont(5,9,font);
    
    
    // formated twice => will format whole String
    str2.applyFont(0,2,font);
    str2.applyFont(0,2,font);

    // wrong order and formated twice => will format 0-6
    str3.applyFont(0,2,font);
    str3.applyFont(5,7,font);
    str3.applyFont(0,2,font);

My "font" just uses a foreground color "font.setColor((short) 2);".

Here is my complete testcase. (I will try to attach it also, but haven't seen 
an option until now to attach a file)

------------------ snip, snip ----
package poi_hssf;

import java.io.*;

import org.apache.poi.hssf.usermodel.*;


public class HSSFRichText
{
  private void newRow()
  {
    this.actRow = this.sheet.createRow(this.nextLineNr);
    this.nextLineNr++;
    this.actCol = 0;
  }


  private HSSFCell appendCell()
  {
    this.actCell = this.actRow.createCell(this.actCol++);
    return (this.actCell);
  }

  
  private void test()
  {
    File file = new File("RichPOI.xls");
    FileOutputStream outStream = null;
    try
    {
      outStream = new FileOutputStream(file);
    }
    catch (FileNotFoundException e)
    {
      System.err.println(e.getStackTrace());
    }
    
    this.wb = new HSSFWorkbook();
    this.sheet = wb.createSheet();

    HSSFFont font;
    font = this.wb.createFont();
    font.setColor((short) 2); // Rot

    HSSFCell cell;
    
    this.newRow();
    HSSFRichTextString str = new HSSFRichTextString
("f0_123456789012345678901234567890123456789012345678901234567890");    
    
    // overlapped range => will format whole String
    str.applyFont(0,7,font);
    str.applyFont(5,9,font);
    cell = this.appendCell();
    cell.setCellValue(str);
    
    
    this.newRow();
    HSSFRichTextString str2 = new HSSFRichTextString
("f1_123456789012345678901234567890123456789012345678901234567890");    
    // formated twice => will format whole String
    str2.applyFont(0,2,font);
    str2.applyFont(0,2,font);
    cell = this.appendCell();
    cell.setCellValue(str2);
    

    this.newRow();
    HSSFRichTextString str3 = new HSSFRichTextString
("f2_123456789012345678901234567890123456789012345678901234567890");    
    // wrong order => will format 0-6
    str3.applyFont(0,2,font);
    str3.applyFont(5,7,font);
    str3.applyFont(0,2,font);
    cell = this.appendCell();
    cell.setCellValue(str3);

    try
    {
      this.wb.write(outStream);
      outStream.close();
    }
    catch (IOException e)
    {
       System.err.println(e.getStackTrace());
    }    
  }
  
  
  public static void main(String[] args)
  {
      HSSFRichText testit = new HSSFRichText();
      testit.test();
  }
  
  
  private int nextLineNr;
  private short actCol;
  private HSSFWorkbook wb;
  private HSSFSheet sheet;
  private HSSFRow actRow;
  private HSSFCell actCell;
}

-- 
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: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message