Copy workbook preserving macros

HI,
i’m using aspose-cells-8.5.2 (i downloaded the package containing also aspose-gridweb-8.5.2, bcprov-jdk16-146).
I have a workbook with different macros, running on buttons click.
I would like to copy this workbook preserving all macros, since i have to use them to write many values in different cells and then generate other documents.

How can I do?
Is there any method I can use?

Thank you

Hi,


Thanks for your query.

1) Do you need to re-save your template Excel file with other name (make a copy of the Excel file) after add/updating data/ contents etc, sure, you may do it via Aspose.Cells APIs. See the sample code below:
e.g
Sample code:

//Load the Excel file (that has vba code/ macros) in it.
Workbook workbook = new Workbook(“Book1.xlsx”);
//
// your code to update the data in the spreadsheet goes here
//

//Save As the Excel file with other name.
workbook.save(“out1.xlsx”);

2) If you need to copy a whole workbook to other workbook using Workbook.copy() method, you may simply do it. When you call destWorkbook.copy(sourceWorkbook) method, the existing macros of destWorkbook will be removed (if there is any) and the macros of sourceWorkbook will be copied to destWorkbook.

Let us know if we can be of any further help.

Thank you.



Hi,


thanks for the answer. Actually, I did the same in my application, but in the new file I don’t find any macro or button defined in the source file.
The difference maybe is given by the file extension, since I have to use .ods instead of .xlsx as you posted in the example. Does the file extension change the behaviour with respect to those elements?

Thank you


Hi,


Thanks for providing further details.

Could you provide us your template file(s) and sample code (runnable) to reproduce the issue on our end, we will check it soon. We will check if it is a bug or some sort of limitation in the APIs, we may log a ticket for it into our database. Also provide some screen shots to highlight which macros are lost in the generated file, this will help us really to evaluate your issue precisely to consequently figure it out soon.

Thank you.

Hi,


here the files. As you can see, the source file “esempio_vuoto (2).ods” contains buttons in each sheet, but the destination file “copia.ods” does not. Moreover, I already notice that images in two sheets were removed by copying this file.
The code is very simple, just fill data in some cells.

Thank you

Hi,


Thanks for the template file and sample code.

After an initial test, I observed the issue as you mentioned by using your sample code with your template ODS file. I found Macros in the ODS file are not retained in the generated ODS file format, each sheet has button(s) in the template ODS file but these buttons are lost in the output ODS file. I have logged a ticket with an id “CELLSJAVA-41485” for your issue. We will look into it soon.

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

Thank you.

@aguidolin

This is to inform you that we have fixed your issue (logged earlier as “CELLSJAVA-41485”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

The issues you have found earlier (filed as CELLSJAVA-41485) have been fixed in Aspose.Cells for Java 18.8. You can also get the latest Aspose.Cells for Java version from Maven repos. with simple configurations. Please see the document for your reference: Installation|Documentation

This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi