You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2009/12/04 09:11:25 UTC

DO NOT REPLY [Bug 48338] New: XSSFSheet autoSizeColumn() on empty RichTextString fails

https://issues.apache.org/bugzilla/show_bug.cgi?id=48338

           Summary: XSSFSheet autoSizeColumn() on empty RichTextString
                    fails
           Product: POI
           Version: 3.5-FINAL
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: poelman@traffic4u.nl


After filling a sheet with data I try to invoke the sheets autoSizeColumn
method on a certain column but get "IllegalArgumentException: Invalid substring
range".

------------------------------------
StackTrace:
------------------------------------
java.lang.IllegalArgumentException: Invalid substring range
 at java.text.AttributedString.addAttribute(AttributedString.java:332)
 at
org.apache.poi.xssf.usermodel.helpers.ColumnHelper.copyAttributes(ColumnHelper.java:447)
    at
org.apache.poi.xssf.usermodel.helpers.ColumnHelper.getColumnWidth(ColumnHelper.java:369)
    at
org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:307)
    at
org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:290)
    at [object where sheet.autoSizeColumn([columnIndex]) is called]
------------------------------------

After testing different columns I came to the conclusion this only happens on
that specific column, even unfilled columns can be autosized. I searched for
the reason inside the cells of that column and discovered this happens only in
a specific situation. If the cell is filled with a RichTextString created with
an empty String and a Font (or XSSFFont) applied the column with this cell in
it can't be autosized. Example:

********** Code **********
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = new wb.createSheet("Test");
CreationHelper ch = wb.getCreationHelper();

XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);

XSSFFont font = wb.createFont();
RichTextString rts = ch.createRichtTextString("");
rts.applyFont(font);
cell.setCellValue(rts);
**************************

The code above does not work unless I invoke ch.createRichtextString(x) where x
is a non empty String. So my fix atm is: ch.createRichTextString(s.isEmpty()?
"" : s); where s is the String.

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

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


DO NOT REPLY [Bug 48338] XSSFSheet autoSizeColumn() on empty RichTextString fails

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=48338

Yegor Kozlov <ye...@dinom.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #1 from Yegor Kozlov <ye...@dinom.ru> 2009-12-04 03:24:54 UTC ---
Fixed in r887160

Yegor

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

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