Unable to set style to cells

Hi Team,

I’m unable to set styles using below java code. Please let me know if i’m doing anything wrong.

public void generateExcel(File csvFile, String outputFile) {
Parser praser;
FileInputStream fis = null;
try {
this.workbook = new Workbook();
this.workbook.setFileFormat(FileFormatType.XLSX);
this.workbook.getWorksheets().removeAt(0);
Worksheet worksheet = (this.workbook.getWorksheets()).add(“Data”);
Cells cells = worksheet.getCells();
fis = new FileInputStream(csvFile);
praser = new CSVParser(fis);

        int rowIndex = 0;

        Style style = new Style();
        style.setBackgroundColor(getColor("#0486e3"));

        while (praser.nextLine()) {
            String[] line = praser.getLineValues();
            if (line != null)
                for (int colIndex = 0; colIndex < line.length; colIndex++) {
                    try {
                        Cell cell = cells.get(rowIndex, colIndex);
                        cell.putValue(line[colIndex]);
                        cell.setStyle(style);
                    } catch (Exception ignored) {

                    }
                }
            rowIndex++;
        }

        this.workbook.save(outputFile, this.saveOptions);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (fis != null)
                fis.close();
        } catch (Exception e) {

        }
    }
}

public Color getColor(String colorStr) {
    return Color.fromArgb(
            Integer.valueOf(colorStr.substring(1, 3), 16),
            Integer.valueOf(colorStr.substring(3, 5), 16),
            Integer.valueOf(colorStr.substring(5, 7), 16));
}

@sukesh.kotian,

Thanks for the sample code and details.

Please change the line of code from your code segment:
i.e.,
style.setBackgroundColor(getColor("#0486e3"));
to:
style.setForegroundColor(getColor("#0486e3"));
style.setPattern(BackgroundType.SOLID);

Let us know if you still find the issue.