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

--- Comment #6 from Bill Somerville <[email protected]> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to