Bug 18090 - [PATCH]Sheet.getColumnWidth sometimes doesnt return the correct width
Summary: [PATCH]Sheet.getColumnWidth sometimes doesnt return the correct width
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: All All
: P3 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-18 06:52 UTC by tanino
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments
I found same bug at org.apache.poi.hssf.model.Sheet#setColumn.So I submitt as a patch. (567 bytes, patch)
2003-04-02 09:08 UTC, Toshiaki Kamoshida
Details | Diff
Testcase to find this problem (1.97 KB, patch)
2003-04-02 15:09 UTC, Toshiaki Kamoshida
Details | Diff
PATCH to fix the case like,a ColumnInfoRecord should be splited to 3 records (1.72 KB, patch)
2003-04-03 04:12 UTC, Toshiaki Kamoshida
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description tanino 2003-03-18 06:52:04 UTC
When the specified column is larger than the value of getFirstColumn by the 
loop of Sheet.getColumnWidth, an exact columninfo object is not returned.

    public short getColumnWidth(short column)
    {
        short            retval = 0;
        ColumnInfoRecord ci     = null;
        int              k      = 0;

        if (columnSizes != null)
        {
            for (k = 0; k < columnSizes.size(); k++)
            {
                ci = ( ColumnInfoRecord ) columnSizes.get(k);
-               if ((ci.getFirstColumn() >= column)
+               if ((ci.getFirstColumn() <= column)
                        && (column <= ci.getLastColumn()))
                {
                    break;
                }
                ci = null;
            }
        }
        if (ci != null)
        {
            retval = ci.getColumnWidth();
        }
        else
        {
            retval = defaultcolwidth.getColWidth();
        }
        return retval;
    }
Comment 1 Toshiaki Kamoshida 2003-04-02 09:08:15 UTC
Created attachment 5602 [details]
I found same bug at org.apache.poi.hssf.model.Sheet#setColumn.So I submitt as a patch.
Comment 2 Toshiaki Kamoshida 2003-04-02 09:11:48 UTC
Sorry, not Sheet#setColumn() but Sheet#setColumnWidth().
Comment 3 Toshiaki Kamoshida 2003-04-02 09:59:48 UTC
The bug Mr.Tanino reported is a simple bug,and I found same problem because of 
another reason.

When user changed plural column's width collectively and saved,the info about 
the operation is exist only the first column's info.(I see the info by XML 
Element generated by MS OfficeXP.Maybe OLE2 file keep it with another sytle,but 
I don't know the spec deeply)
So,user can't get correct width about rest columns by Sheet#getColumnWidth().
Comment 4 Toshiaki Kamoshida 2003-04-02 10:10:41 UTC
...Sorry,I didn't read org.apache.poi.hssf.record.ColumnInfoRecord.
The Logic I said is already implemented.
...So,why a problem happen in my local env?hmm...
Comment 5 Toshiaki Kamoshida 2003-04-02 11:21:54 UTC
Very sorry,I tested POI without Mr.tanino's patch X(
Comment 6 Avik Sengupta 2003-04-02 12:07:47 UTC
Sorry, now I am confused. Which patch should i apply?
Comment 7 Toshiaki Kamoshida 2003-04-02 15:09:27 UTC
Created attachment 5606 [details]
Testcase to find this problem
Comment 8 Toshiaki Kamoshida 2003-04-02 15:24:04 UTC
Because I am stupid,I am sorry to make you confused...X(

The attatchment I submitted is a copy of that Mr.Tanino wrote.
To fix org.apache.poi.hssf.model.Sheet#getColumnWidth(),please apply it.
And I found same mistake in #setColumnWidth(),so in the patch I apply to
fix it.


BTW,
Now I submitted a testcase testing #getColumnWidth() and #setColumnWidth().
And I found a new problem with the testcase...

By the testcase,ColumnInfoRecord should be splited to 3 records,ColumnNo=5, and 
ColumnNo=6,and ColumnNo=7~10. But now there is no implementation like so in 
#setColumnWidth().
So the last asserEquals() block in the testcase will throw a Error.
Comment 9 Toshiaki Kamoshida 2003-04-03 04:12:31 UTC
Created attachment 5614 [details]
PATCH to fix the case like,a ColumnInfoRecord should be splited to 3 records
Comment 10 Andy Oliver 2003-04-11 03:00:50 UTC
Committed.  Please cross check.  unit tests passed.