导出Excel,根据状态(open/closed)设置背景色,open,背景色为白色,closed灰色导出结果第二行closed本为灰色却变成了白色,第六行状态open背景色应为白色却成了灰色,
代码: private void rowsPrint(ExcelXmlParser parser, HttpServletResponse resp) throws WriteException, IOException {
ExcelRow[] rows = parser.getGridContent();

for (int i = 0; i <rows.length; i++) {
String[] cells = rows[i].getCells();

//标记当前行是否为Closed
boolean isClosed=false;
sheet.setRowView(i + headerOffset, 400);

Cell cell=sheet.getCell(11, i);//业务状态
if(cell.getContents().equals("Closed")){
isClosed=true;
}
for (int j = 0; j < cells.length; j++) {
WritableFont font = new WritableFont(WritableFont.TAHOMA, 10);
WritableCellFormat f = new WritableCellFormat (font);
if(isClosed){
f.setBackground(Colour.GRAY_25);//#E3EFFF
}else{
f.setBackground(Colour.WHITE);
}

解决方案 »

  1.   


     Cell cell=sheet.getCell(11, i+1)//业务状态
      

  2.   


    for (int j = 0; j < cells.length; j++) {
                    WritableFont font = new WritableFont(WritableFont.TAHOMA, 10);
                    WritableCellFormat f = new WritableCellFormat (font);
                                    if(isClosed){
                        f.setBackground(Colour.GRAY_25);//#E3EFFF
                    }else{
                        f.setBackground(Colour.WHITE);
                    }
    你这个背景颜色设置到哪个CELL上了???
      

  3.   

     Cell cell=sheet.getCell(11, i);//业务状态
                if(cell.getContents().equals("Closed")){
                    isClosed=true;
                }
    调试下,看下取出来得第一行的状态是Closed么?是不是取出的数据有问题。
      

  4.   

    Cell cell=sheet.getCell(11, i);//业务状态
      if(cell.getContents().equals("Closed")){
      isClosed=true;
      }
    调试下,看下取出来得第一行的状态是Closed么?是不是取出的数据有问题。