Macro code replacement crush xls-file if it contains cyrillic names

Hello.
In my project I have xsl-files with VBA module witch contains macros named “FinalMacros”. At runtime I’m modifining module code (add macro “Auto_open”) and save file. When I open saved file in MS Excell, “Auto_open” macro start executing and throw exception.
The couse of exception is cyrillic names in VBA-project


After macro code replacing and saving file project looks like:



If VBA-project not have cyrillic names, file save correct.

Code snippet:
public class Main {

public static void main(String[] args) throws Exception {
processFile("Example1.xls");
processFile("Example2.xls");
}

public static void processFile(String fileName) throws Exception {
Workbook workbook_;
String appPath = System.getProperty("user.dir");
FileInputStream fileInputStream = new FileInputStream(appPath + "\\" + fileName);
try {
workbook_ = new Workbook(fileInputStream);
workbook_.getWorksheets().setActiveSheetIndex(0);

VbaModuleCollection modules = workbook_.getVbaProject().getModules();
boolean hasFinalMacros = false;
for (int i = 0; i < modules.getCount(); i++) {
VbaModule module = modules.get(i);
String code = module.getCodes();
if (code.toLowerCase().contains("finalmacros")) {
module.setCodes(code + "\n" +
"Private Sub Auto_open()\n" +
" Call FinalMacros\n" +
"End Sub");
break;
}
}
workbook_.save(appPath + "\\" + fileName.replace(".xls", "Result.xls"));
} finally {
fileInputStream.close();
}
}
}
Example files attached.

Hi,


Thanks for providing us template files and sample code.

After an initial test, I observed the issue as you mentioned by using your sample code with your template files. I found if the workbook contains cyrillic worksheet names, Macro code replacement crushes the XLS file. I evaluated both cases (one with cyrillic names and other without cyrillic names). I noticed the issue with the output Excel file created from Example1.xls.

I have logged a ticket with an id “CELLSJAVA-41483” for your issue. We will look into it soon.

Once we have any update on it, we will let you know here.

Thank you.


Hi,


This is to update you that we have fixed your issue “CELLSJAVA-41483 now. We will provide the fix after performing QA and including other enhancements and fixes.

Once the fix is available, we will let you know here immediately.

Thank you.


The issues you have found earlier (filed as CELLSJAVA-41483) have been fixed in

Aspose.Cells for Java (Download | Maven)

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