Incorrect background color in JPG output of excel table

Hello,

I am using Aspose.Cells v18.5 to generate JPG of table- “Table1” in the attached excel file. The background color of table cells is incorrect in the JPG output.

This issue seems to be a break in functionality. It used to work fine till some previous version of aspose.cells. So this a critical issue for us and we need a fix for this asap.

PFA below the source excel and sample code to generate the PNG:
attachments.zip (3.3 MB)

Can you please analyse this issue.

Thanks,
Neha

@Neha_Gautam,

Thanks for the template file and sample code.

After an initial test, I am able to observe the issue as you mentioned by using your sample code with your template file. I found incorrect background color for the table cells when rendering worksheet to image to JPG file format.

I have logged a ticket with an id “CELLSJAVA-42679” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

@Neha_Gautam

The efficient way is just set a proper print area, then render to image:

 String worksheetName = "Sheet1";
 String tableName = "Table1";

 Workbook workbook = new Workbook("test.xlsx");
 Worksheet worksheet = workbook.getWorksheets().get(worksheetName);

 ListObject table = worksheet.getListObjects().get(tableName);

 //set print area to output
 String leftTopCellName = CellsHelper.cellIndexToName(table.getStartRow(), table.getStartColumn());
 String rightBottomCellName = CellsHelper.cellIndexToName(table.getEndRow(), table.getEndColumn());
 worksheet.getPageSetup().setPrintArea(leftTopCellName + ":" + rightBottomCellName);

 worksheet.getPageSetup().setTopMargin(0);
 worksheet.getPageSetup().setBottomMargin(0);
 worksheet.getPageSetup().setRightMargin(0);
 worksheet.getPageSetup().setLeftMargin(0);

 ImageOrPrintOptions imgOptionsForTable = new ImageOrPrintOptions();
 imgOptionsForTable.setImageType(ImageType.JPEG);
 imgOptionsForTable.setHorizontalResolution(600);
 imgOptionsForTable.setVerticalResolution(600);
 imgOptionsForTable.setOnePagePerSheet(true);
 imgOptionsForTable.setOnlyArea(true);

 SheetRender sr = new SheetRender(worksheet, imgOptionsForTable);
 sr.toImage(0, output.jpg); 

If you still want to use copy to a new workbook, and then render to image, you should also copy theme.

 ...
 Workbook newWorkbook = new Workbook(FileFormatType.XLSX);
 //copy theme
 newWorkbook.copyTheme(workbook);
 newWorkbook.setDefaultStyle(sourceRange.getWorksheet().getWorkbook().getDefaultStyle());
 ...