Thanks for the quick attention on this. I have not tried your proposed code changes yet but I will soon. In the meantime, I am noticing a much greater issue that needs attention. Apparently Aspose.Cells is having a problem returning an HTML string from a workbook that it creates and that MS Excel can successfully open. Originally, I have about 20 HTML views I need to capture from a workbook using Aspose.Cells but some of them take over 4 minutes ( maybe this is another issue that can be looked at ). I thought to take snapshots of them into a new workbook using the Range.copy() to see if the performance issue was related to the much larger workbook BUT I am getting a [java.lang.ArrayIndexOutOfBoundsException]! At first this was an in-memory operation but I got the aforementioned exception so I resorted to saving it as a file and then tried processing the file but I get the same exception. I want to keep this as an in-memory operation without creating a physical file and I know how to do that BUT the exception issue needs to be resolved. Please help!
The stack trace is below and the attached screenshot also shows that the error is coming from line 393 at the Workbook.save() function.
---------stack—
35488 [ERROR] o.a.c.c.C.[.[.[.[.c.c.b.epm.AppConfig] : Servlet.service() for servlet [com.private.private.private.AppConfig] in context with path [] threw exception [java.lang.ArrayIndexOutOfBoundsException: -1] with root cause
java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.elementData(ArrayList.java:418)
at java.util.ArrayList.get(ArrayList.java:431)
at com.aspose.cells.zahj.g(Unknown Source)
at com.aspose.cells.zahj.a(Unknown Source)
at com.aspose.cells.zahl.b(Unknown Source)
at com.aspose.cells.zahh.a(Unknown Source)
at com.aspose.cells.zahm.b(Unknown Source)
at com.aspose.cells.zahm.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at com.private.private.private.XXXWorkbook.getUnsanitizedHtmlFromRange(XXXWorkbook.java:393)
---------code—
private String getUnsanitizedHtmlFromRange(Range sourceRange) throws Exception {
Stopwatch stopwatch = Stopwatch. createStarted ();
//Set the sheet where the namedRange is found as the active sheet because //we are forcing our HtmlSaveOptions to only export the active worksheet. Workbook targetWorkbook = new Workbook();
Cells targetCells = targetWorkbook.getWorksheets().get(0).getCells();
Range targetRange = targetCells.createRange(0, 0, sourceRange.getRowCount(), sourceRange.getColumnCount());
PasteOptions pasteOptions = new PasteOptions();
//pasteOptions.setPasteType(PasteType.COLUMN_WIDTHS + PasteType.ROW_HEIGHTS + PasteType.FORMATS + PasteType.VALUES_AND_NUMBER_FORMATS); pasteOptions.setPasteType(PasteType. ALL );
targetRange.copy(sourceRange, pasteOptions);
Worksheet targetWorksheet = targetRange.getWorksheet();
targetWorkbook.getWorksheets().setActiveSheetIndex(targetWorksheet.getIndex());
targetWorksheet.getPageSetup().setPrintArea(targetRange.getAddress());
targetWorkbook.save( "d: \ " + sourceRange.getWorksheet().getName() + ".xlsx" );
//Now set the necessary HtmlSaveOptions so that we can get our HTML view. HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat. HTML );
options.setDisableDownlevelRevealedComments( true );
options.setExcludeUnusedStyles( true );
options.setExportActiveWorksheetOnly( true );
options.setExportDocumentProperties( false );
options.setExportFrameScriptsAndProperties( false );
options.setExportImagesAsBase64( false );
options.setExportPrintAreaOnly( true );
options.setExportSimilarBorderStyle( true );
options.setExportWorkbookProperties( false );
options.setExportWorksheetCSSSeparately( false );
options.setExportWorksheetProperties( false );
options.setParseHtmlTagInCell( true );
options.setHtmlCrossStringType(HtmlCrossType. FIT_TO_CELL );
//Save the file to BAOS, trim the BOM, and return as string ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Workbook targetWorkbook2 = new Workbook( "d: \ AXDI_Restricted_Test.xlsx" ); // + sourceRange.getWorksheet().getName() + ".xlsx"); targetWorkbook2.save(outputStream, options);
String trimmed = trimUTF8BOM (outputStream.toString( "UTF-8" ).replaceAll( "mso-.+:.+;" , "" ));
logger .info(String. format ( "<— Time taken to get unsanitized HTML(%s) from Range: %s" , trimmed.length(),
stopwatch.toString()));
return trimmed;
}
Aspose Error.zip (160.6 KB)