We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Named range to image transformation gives invalid image

HI,

I am using aspose-cells-7.7.1.5.jar.
I am using the below code to copy named range to a new workbook, then generate an image of named range.

Step 1. copy named range to a new workbook
private static Workbook createWorkBook(final Cells cellsToBeCopied, final Range namedRange) throws Exception {
Workbook workbook = new Workbook();
// As this workbook is blank workbook so take cells of first worksheet of this workbook
Cells cells = workbook.getWorksheets().get(0).getCells();

int totalNoOfRows = namedRange.getRowCount();
int totalNoOfColumns = namedRange.getColumnCount();

cells.setStandardHeight(namedRange.getRowHeight());
cells.setStandardWidth(namedRange.getColumnWidth());

// Set height of each row as the height of actual rows of table
for (int row = 0; row < totalNoOfRows; row++) {
cells.setRowHeight(row, cellsToBeCopied.getRowHeight(namedRange.get(row, 0).getRow()));
}

// Set width of each column as the width of actual columns of table
for (int column = 0; column < totalNoOfColumns; column++) {
cells.setColumnWidth(column, cellsToBeCopied.getColumnWidth(namedRange.get(0, column).getColumn()));
}

// Copy data of table from worksheet to newly created workbook cells
for (int row = 0; row < totalNoOfRows; row++) {
for (int column = 0; column < totalNoOfColumns; column++) {
Cell copiedFrom = namedRange.get(row, column);
Cell copyTo = cells.get(row, column);

copyTo.setHtmlString(copiedFrom.getHtmlString());
copyTo.setStyle(copiedFrom.getDisplayStyle());
}
}

return workbook;
}

Step 2 : generate image
Workbook book = createWorkBook(cells, namedRange);
com.aspose.cells.Worksheet sheet = book.getWorksheets().get(0);
SheetRender sr = new SheetRender(sheet, imageOrPrintOptions);
sr.toImage(0, outputFile.getAbsolutePath());

The above code works fine except for named range IS&GS!Z_086B3EA5_D30F_4E0E_ADC1_FCC5B0EA4601_.wvu.PrintArea on worksheet IS&GS. The image genereted in this case downot have any cell value its kind of blank image, no data.
Attached is the excel doc.


Thanks & Regards,
Jaspreet


In addition to the above post, the worksheet IS&GS, shows me name ranges of type IS&GS!Z_086B3EA5_D30F_4E0E_ADC1_FCC5B0EA4601_.wvu.PrintArea, that I dont get to see in the Name box at the left end of the formula bar on opening the attached excel. Could you help me where & how these named ranges were created.


Thanks & regards,
Jaspreet

I have observed that if columns are collapsed, the image is blank, if columns ungrouped the image is fine.

Attached is the excel with grouped columns on worksheet IS&GS.

Hi Jaspreet,

Thanks for your posting and using Aspose.Cells.

Please download and try the latest version: Aspose.Cells
for Java v8.1.0.2
, it should fix your issue.

If your issue still occurs, then provide us your runnable sample code and it would be helpful if you could also provide us a simple xls/xlsx file replicating this issue.

We will look into it and help you asap.