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