Quantcast

DO NOT REPLY [Bug 51037] New: setDefaultColumnStyle() in XSSFSheet not working

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO NOT REPLY [Bug 51037] New: setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

           Summary: setDefaultColumnStyle() in XSSFSheet not working
           Product: POI
           Version: 3.8-dev
          Platform: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
        AssignedTo: [hidden email]
        ReportedBy: [hidden email]


Created an attachment (id=26865)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26865)
Full test class

The method setDefaultColumnStyle(int column, CellStyle style) is not having any
effect in an XSSFWorkbook. This is my test code:

public static void columnStyles(boolean xml) throws IOException {
    Workbook wb = xml ? new XSSFWorkbook() : new HSSFWorkbook();

    CellStyle blueStyle = wb.createCellStyle();
    blueStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());
    blueStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    CellStyle pinkStyle = wb.createCellStyle();
    pinkStyle.setFillForegroundColor(IndexedColors.PINK.getIndex());
    pinkStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    Sheet s1 = wb.createSheet("Pretty columns");

    s1.setDefaultColumnStyle(4, blueStyle);
    s1.setDefaultColumnStyle(6, pinkStyle);

    Row r = s1.createRow(7);
    r.createCell(1).setCellStyle(pinkStyle);
    r.createCell(8).setCellStyle(blueStyle);

    fill(s1.createRow(3), "The quick brown fox jumps over the lazy
dog".split("\\s+"));
    save(wb, (xml ? "columnStyles.xlsx" : "columnStyles.xls"));
}

The styles are applied to the individual cells via setCellStyle(), but not to
the columns.

Everything works as expected when using an HSSFWorkbook.

--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO NOT REPLY [Bug 51037] setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

[hidden email] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|                            |Windows 7

--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO NOT REPLY [Bug 51037] setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

Nick Burch <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO
         OS/Version|                            |All

--- Comment #1 from Nick Burch <[hidden email]> 2011-04-07 07:11:29 EDT ---
There's code in XSSFSheet that looks to be doing the right thing, no it isn't
missing code

Could you try one thing to help track down what's wrong? Steps are:
* Create a .xlsx file with a different style
* Take a copy
* Using Excel, apply that existing style as the default to a column
* Using POI, apply that existing style as the default to a column
* Unzip both resuling files (.xlsx is a zip of xml files)
* Try to spot what POI did differently to Excel

Once we can narrow down what Excel is doing differently, we can then try to fix
it in POI.

--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO NOT REPLY [Bug 51037] setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

[hidden email] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

--- Comment #2 from [hidden email] 2011-04-07 10:34:59 EDT ---
If I look at "sheet1.xml", the Excel-generated file has
    <dimension ref="B1:E1"/>

where the POI-generated file had
    <dimension ref="B1"/>

and Excel has
    <col min="2" max="2" width="9.140625" style="1"/>
    <col min="5" max="5" width="9.140625" style="1"/>

where POI has
    <col min="2" max="2" style="1" width="9.140625" collapsed="false"/>
    <col min="5" max="5" style="0"/>

"styles.xml" is not substantially different; the custom style is stored as
    <cellStyle name="PurpleStyle" xfId="1"/>

In both cases, column B (2) was the column which already had the style. Column
E (5) was the one which I copied the style to in Excel or POI respectively.

So it looks like POI is creating a column entry in the worksheet file, but not
storing the style.

Hope that helps.

--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO NOT REPLY [Bug 51037] setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

--- Comment #3 from [hidden email] 2011-04-07 10:47:59 EDT ---
Update: I've just simplified my test code, and this time POI managed to update
the spreadsheet correctly.

If I use "workbook.getCellStyleAt((short) 1)" to reference the style, then it
works. If I use "cell.getCellStyle()", it doesn't.

--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO NOT REPLY [Bug 51037] setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

--- Comment #4 from [hidden email] 2011-04-07 11:59:22 EDT ---
*Correction*!

The original code does in fact fill the columns as I asked. However, the column
widths are then set to 0, which made me originally think that the code had not
done anything.

In addition, when I unhide the columns, I find that the newly-created cells had
not respected the default column style, but had been created with a blank
(unfilled) background.

--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO NOT REPLY [Bug 51037] setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

Nick Burch <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #5 from Nick Burch <[hidden email]> 2011-04-14 14:08:21 EDT ---
I've just added a unit test in r1092423 for the case you describe. However, it
does all seem to be working fine for me - the column gets set up with the style
as you'd expect. I can't replicate your problem of the style not being set.

Are you able to compare my test code to yours to see what's happening
differently?

--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO NOT REPLY [Bug 51037] setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

--- Comment #6 from Bill Somerville <[hidden email]> 2011-04-27 09:49:01 EDT ---
(In reply to comment #5)
> I've just added a unit test in r1092423 for the case you describe. However, it
> does all seem to be working fine for me - the column gets set up with the style
> as you'd expect. I can't replicate your problem of the style not being set.
>
> Are you able to compare my test code to yours to see what's happening
> differently?

Hi.  I'm having what I think to be the same problem.  The code below reliably
reproduces the problem.  Note that the same code works fine (as expected) with
HSSFWorkbook, and note also the workaround:

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import java.io.FileOutputStream;

public class Test
{

    public static void main(String args[])
    {
        try
        {
            Test test = new Test();
            test.run();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    Test()
    {
    }

    void run()
            throws Exception
    {
    // Problem: column 0 ends up with zero width and white background in
XSSFWorkbook; looks OK in HSSFWorkbook
        Workbook workbook = new XSSFWorkbook();
    FileOutputStream stream = new FileOutputStream("C:\\Temp\\Foo.xlsx");
        //Workbook workbook = new HSSFWorkbook();
    //FileOutputStream stream = new FileOutputStream("C:\\Temp\\Foo.xls");
    Sheet sheet = workbook.createSheet();
    CellStyle styleGray = workbook.createCellStyle();

    styleGray.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    styleGray.setFillPattern(CellStyle.SOLID_FOREGROUND);

    sheet.setDefaultColumnStyle(0, styleGray);

    Row row = sheet.createRow(0);
    Cell cell;
    int column = 0;
    cell = row.createCell(column);
    cell.setCellValue("I'm gray");
    // Workaround: cell.setCellStyle(sheet.getColumnStyle(column));
    // Workaround: sheet.autoSizeColumn(column);

    cell = row.createCell(++column);
    cell.setCellValue("I'm white");
    workbook.write(stream);
    stream.flush();
    }
}

--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO NOT REPLY [Bug 51037] setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

Bill Somerville <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Bug 51037] setDefaultColumnStyle() in XSSFSheet not working

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://issues.apache.org/bugzilla/show_bug.cgi?id=51037

--- Comment #7 from sumedh <[hidden email]> ---
I tried with SXSSFSheet and it doesn't work there either.

--
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...