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 47862] Not setting the correct columnwidth in XSSFSheet
Date Tue, 22 Sep 2009 14:29:46 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=47862

--- Comment #3 from bob Stox <bstox@yahoo.com> 2009-09-22 07:29:43 PDT ---
After looking at what Yegor did for bug 47581, I was debugging the
setColumnWidth in class ColumnHelper.  I add the following line:
System.out.println(col.toString);

And the result was the following:
<xml-fragment min="1" max="5" customWidth="true" width="15.77734375"
collapsed="false"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"/>

I saw the min, max to be the columns that have the same width in my
spreadsheet.

I first tried just setting the min/max for that column and that worked for the
one column but all the other columns were reset to the default width. So I then
came up with the following solution and it seems to work.

    public void setColWidth(long index, double width) {
        CTCol col = getOrCreateColumn1Based(index+1, false);
        if (col.getMax() != col.getMin()){
            double old_width = col.getWidth();
            long from_column = col.getMin();
            long to_column = col.getMax();
            col.setMin(index+1);
            col.setMax(index+1);    
            // Check if there are any columns to the left of columns to be
reset
            if (index >= from_column && index > 0){
                CTCol newCol = getOrCreateColumn1Based(index, false);
                newCol.setMin(from_column);
                newCol.setMax(index);
                setColumnAttributes(col,newCol);
                newCol.setWidth(old_width);
            }
            // Check if there are any columns to the left of columns to be
reset
            if ((index+2) <= to_column){
                CTCol newCol = getOrCreateColumn1Based((index+2), false);
                newCol.setMin(index+2);
                newCol.setMax(to_column);
                setColumnAttributes(col,newCol);
                newCol.setWidth(old_width);
            }
        }
        col.setWidth(width);
    }

-- 
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


Mime
View raw message