imgOptions.setOnlyArea(true); is not working in aspose cells 7.7.1

ImageOrPrintOptions setOnlyArea(true) is not working in 7.7.1 release but works fine in 7.6.0.


Hi,


Could you provide your template Excel file and mention the name of the worksheet which you are converting to image with “setOnlyArea()” on, we will check your issue soon. And, if you are creating the spreadsheet on the fly, please provide your sample code (runnable) here.

Thank you.

Here is the code:

 private void tableToImage(final Worksheet worksheet, final ListObject table, final String outPutFilePath, final ImageOrPrintOptions imageOrPrintOptions)
throws FileNotFoundException, Exception {
Workbook workbook = createWorkBook(worksheet, table);
Worksheet sheet = workbook.getWorksheets().get(0);
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageFormat(imageOrPrintOptions.getImageFormat());
imgOptions.setOnePagePerSheet(true);
imgOptions.setHorizontalResolution(imageOrPrintOptions.getHorizontalResolution());
imgOptions.setVerticalResolution(imageOrPrintOptions.getVerticalResolution());
imgOptions.setOnlyArea(true);
SheetRender sr = new SheetRender(sheet, imgOptions);
sr.toImage(0, outPutFilePath);
}
private Workbook createWorkBook(final Worksheet worksheet, final ListObject listObject) 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();
Cells cellsTobeCopied = worksheet.getCells();
int totalNoOfRows = listObject.getEndRow() - listObject.getStartRow() + 1;
int totalNoOfColumns = listObject.getEndColumn() - listObject.getStartColumn() + 1;
cells.setStandardHeight(cellsTobeCopied.getStandardHeight());
cells.setStandardWidth(cellsTobeCopied.getStandardWidth());
// 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(row));
}
// 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(column));
}
// 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 = worksheet.getCells().get(listObject.getStartRow() + row, listObject.getStartColumn() + column);
Cell copyTo = cells.get(row, column);
copyTo.setHtmlString(copiedFrom.getHtmlString());
}
}
// Create table in newly created workbook
ListObjectCollection tables = workbook.getWorksheets().get(0).getListObjects();
tables.add(0, 0, totalNoOfRows - 1, totalNoOfColumns - 1, listObject.getShowHeaderRow());
ListObject table = tables.get(tables.getCount() - 1);
table.setTableStyleName(listObject.getTableStyleName());
return workbook;
}

I attached output of both the versions. 7.6.0 return me only table but 7.7.1 returns me the table surrounded with white area

Hi,


Please remove the line in your codes:
i.e.
imgOptions.setOnePagePerSheet(true);  

it would work fine.

Let us know if you still find the issue.

Thank you.

Thanks. Now it works fine.

Hi Ashish,

Good to know that you are up and running again. Please feel free to write back any time in case you need our further assistance.

Hi
I am also using aspose cells 7.7.1 in that I am not able to change the value for worksheet.getOutline().SummaryColumnRight from true to false.Can you please help me with this?

@Ruchita123,

Since you are using an older version of the API, so we cannot help you much. Please try using latest version/fix: Aspose.Cells for Java v22.12 (Releases | Maven). In case, you have this issue with latest version, kindly share your template Excel file, sample code segment and output file, we will check it soon.

PS. please zip the files prior attaching.