【问题标题】:Set backgroundcolor HSSFRow [duplicate]设置背景色 HSSFRow [重复]
【发布时间】:2014-07-02 03:06:57
【问题描述】:

当批准日期晚于今天时,我正在尝试更改行的颜色。在那一刻,行应该用红色着色......知道为什么这段代码不起作用吗?

//  Create a row and put some cells in it. Rows are 0 based.
Row = sheet.createRow((short) count);

if(wdContext.nodeRecallStore().getRecallStoreElementAt(i).getApprovaldate().after(today))
//  {
        HSSFCellStyle style = wb.createCellStyle();
        style.setFillBackgroundColor(new HSSFColor.RED().getIndex());
        Row.setRowStyle(style);

// }

【问题讨论】:

    标签: java excel colors apache-poi


    【解决方案1】:

    这有点令人困惑,但您必须设置前景色和填充图案。

     final HSSFCellStyle cell = (HSSFCellStyle) workbook.createCellStyle();
        cell .setFillForegroundColor( ... );
        cell .setFillPattern(  CellStyle.SOLID_FOREGROUND );
    

    更新为 CellStyle.SOLID_FOREGROUND

    【讨论】:

    • style.setFillPattern(FillPatternType.SOLID_FOREGROUND);我收到此函数需要“Short”而不是“FillPatternType”的错误
    • 抱歉,请使用 CellStyle.SOLID_FOREGROUND
    猜你喜欢
    • 2013-08-12
    • 2011-01-09
    • 2011-08-31
    • 2018-06-15
    • 2023-03-25
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 2018-09-14
    相关资源
    最近更新 更多