Inserting rows removes macro assignment in button for ONLYOFFICE
fgimian opened this issue · comments
Description
You may assign a macro to a text box or shape in ONLYOFFICE spreadsheets. When using the InsertRows
function in excelize and saving such spreadsheets, the macro assignment is lost.
Steps to reproduce the issue:
- Create an empty spreadsheet in ONLYOFFICE
- In the ribbon, click Insert > Text Box and create a text box with some text
- Right-click the text box and click Assign Macro and assign Macros 1
- Write some Go code using excelize to open the spreadsheet, call
InsertRows
and thenSave
and observe that the saved spreadsheet loses the macro assignment for the text box
I have attached an example spreadsheet below:
You can open this in ONLYOFFICE and click the Run Macro button which will place some text in A1.
Now, run the following code to open, insert rows and save the spreadsheet:
package main
import (
"log"
"github.com/xuri/excelize/v2"
)
func main() {
f, err := excelize.OpenFile("ONLYOFFICE Macro Example.xlsx")
if err != nil {
log.Fatalf("unable to open spreadsheet: %v", err)
}
defer f.Close()
if err := f.InsertRows("Sheet1", 5, 1); err != nil {
log.Fatalf("unable to insert rows: %v", err)
}
if err := f.SaveAs("Output.xlsx"); err != nil {
log.Fatalf("unable to save file: %v", err)
}
}
If you now open Output.xlsx, you'll see that you can no longer click the button as no macro is assigned. This only seems to occur when inserting rows; updating values doesn't cause the problem.
Update: This problem occurs with any operation which inserts or removes rows and columns
Describe the results you received:
The text box is no longer clickable after saving and the macro assignment is lost.
Describe the results you expected:
The macro assignment should be retained.
Output of go version
:
go version go1.22.3 windows/amd64
Excelize version or commit ID:
v2.8.1
I also tested this with the latest master
branch on GitHub with the same results sadly.
Environment details (OS, Microsoft Excel™ version, physical, etc.):
Windows 11 Pro
ONLYOFFICE 8.1
Thanks in advance for all your help
Fotis
After examining the compressed XML, I can see the problem occurs in the drawing object / text box (under xl\drawings\drawing1.xml
).
The assignment is present here:
<xdr:sp macro="jsaProject_aebd0d9e67b34cf89bc153ffe4dff966">
But is lost after saving when rows or columns are inserted or deleted:
<xdr:sp>
Cheers
Fotis
Thanks for your feedback. This issue has been fixed, please upgrade to the master branch code by go get -u github.com/xuri/excelize/v2@master
, and this patch will be released in the next version.
Thanks for your feedback. This issue has been fixed, please upgrade to the master branch code by
go get -u github.com/xuri/excelize/v2@master
, and this patch will be released in the next version.
Thank you so much for the fix, works perfectly! 😄