Exception when saving XLSX document

After certain manipulations on the XLSX document and saving it back I have an exception when saving it back to file.

Not sure if you need this, but the meaning of the manipulations are to insert back text into file, preserving formatting:
Just some text for test
And I would like to insert into "Just some " -> "T- Just some “; “text for” -> “T-text for”; " test” ->“T-test”. So after the insertion I expect it to look as:
T-Just some T-text for T-test

I managed to localize what exactly leads to it and put up snippet that reproduces the issue:

License license = new License();
license.setLicense(new FileInputStream(“Aspose.Total.Java.lic”));
Workbook wb = new Workbook(PATH_TO_FILE + “\” + FILE_NAME);
String newChartTitle = “T-My chart title”;
Title title = wb.getWorksheets().get(0).getCharts().get(0).getTitle();
FontSetting[] fontSettings = title.getCharacters();
ArrayList fontList = new ArrayList(fontSettings.length);
for (FontSetting fontSetting : fontSettings)
fontList.add(fontSetting.getFont());
LinkedList endPositionList = new LinkedList();
endPositionList.add(4);
endPositionList.add(16);

title.setText(newChartTitle);
int trailingStartOfFormatChunk = 0;
for (int fontIndex = 0; fontIndex < fontList.size(); fontIndex++)
{
if (fontIndex == endPositionList.size())
break;
int endPosition = endPositionList.get(fontIndex);
if ((fontIndex == fontList.size() - 1) && fontList.size() < endPositionList.size())
endPosition = newChartTitle.length();
copyFontSettings(title.characters(trailingStartOfFormatChunk, endPosition).getFont(), fontList.get(fontIndex));
trailingStartOfFormatChunk = endPositionList.get(fontIndex);
}
wb.save(new FileOutputStream(PATH_TO_FILE + “\modified” + FILE_NAME), FileFormatType.XLSX);



private void copyFontSettings(Font formattedElement, Font templateElement)
{
formattedElement.setBold(templateElement.isBold());
formattedElement.setCapsType(templateElement.getCapsType());
formattedElement.setColor(templateElement.getColor());
formattedElement.setDoubleSize(templateElement.getDoubleSize());
formattedElement.setItalic(templateElement.isItalic());
formattedElement.setName(templateElement.getName());
formattedElement.setNormalizeHeights(templateElement.isNormalizeHeights());
formattedElement.setStrikeout(templateElement.isStrikeout());
formattedElement.setSubscript(templateElement.isSubscript());
formattedElement.setSuperscript(templateElement.isSuperscript());
formattedElement.setUnderline(templateElement.getUnderline());
formattedElement.setScriptOffset(templateElement.getScriptOffset());
formattedElement.setStrikeType(templateElement.getStrikeType());
if (null != templateElement.getThemeColor())
formattedElement.setThemeColor(templateElement.getThemeColor());
}


Could you tell me what is causing the problem, is there any chance I could avoid it?
Below is the callstack which, as you understand, doesn’t give me much information, and file is in attachments.
java.lang.StringIndexOutOfBoundsException: String index out of range: 20
at java.lang.String.substring(String.java:1934)
at com.aspose.cells.gf.a(Unknown Source)
at com.aspose.cells.gf.a(Unknown Source)
at com.aspose.cells.gf.a(Unknown Source)
at com.aspose.cells.gf.f(Unknown Source)
at com.aspose.cells.gf.a(Unknown Source)
at com.aspose.cells.gJ.a(Unknown Source)
at com.aspose.cells.gJ.b(Unknown Source)
at com.aspose.cells.gJ.g(Unknown Source)
at com.aspose.cells.gJ.a(Unknown Source)
at com.aspose.cells.gI.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at test.project.MainClass.parse(MainClass.java:84)
at test.project.MainClass.main(MainClass.java:289)

Hi,

Thanks for your posting and using Aspose.Cells for Java.

We were able to replicate this exception using your code. We have logged this issue in our database. We will look into it and resolve this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSJAVA-40519.

Hi,

Please try the new fix/version: Aspose.Cells for Java v7.4.3.5 (attached). We have fixed the issue.

You may change the source code i.e…, title.characters(trailingStartOfFormatChunk, endPosition)

to:

title.characters(trailingStartOfFormatChunk, endPosition - trailingStartOfFormatChunk)

to avoid the exception directly by using old version.

The original method is FontSetting characters(int
startIndex, int length). The second parameter is length of title text, not the ending index of title text.

Thank you.

Thank you for clarification and fix.
Your developers should consider not obfuscating your sources and using javadocs.

The issues you have found earlier (filed as CELLSJAVA-40519) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.