Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parentheses in formulas get cut out when inserting new columns or rows #1861

Closed
losdmi opened this issue Mar 22, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@losdmi
Copy link

losdmi commented Mar 22, 2024

Description

When adding columns or rows and formulas need to be adjusted, the inner parentheses got cut out therefore resulting in corrupted formula

Steps to reproduce the issue:
Heres example programm

package main

import (
	"fmt"

	"github.com/xuri/excelize/v2"
)

func main() {
	f := excelize.NewFile()
	defer func() {
		if err := f.Close(); err != nil {
			fmt.Println(err)
		}
	}()
	// Create a new sheet.
	index, err := f.NewSheet("Sheet2")
	if err != nil {
		fmt.Println(err)
		return
	}
	// Set value of a cell.
	f.SetCellFormula("Sheet2", "A2", "(1-0.5)/2")
	f.InsertCols("Sheet2", "A", 1)
	// Set active sheet of the workbook.
	f.SetActiveSheet(index)
	// Save spreadsheet by the given path.
	if err := f.SaveAs("Book1.xlsx"); err != nil {
		fmt.Println(err)
	}
}

Describe the results you received:
=1-0,5/2
Describe the results you expected:
=(1-0,5)/2
Output of go version:

go version go1.21.3 darwin/arm64

Excelize version or commit ID:

2.8.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):
MacOS

@xuri xuri added the bug Something isn't working label Mar 23, 2024
@xuri xuri closed this as completed in 703b737 Mar 25, 2024
@xuri
Copy link
Member

xuri commented Mar 25, 2024

Thanks for your issue. This bug 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: Bugfix
Development

No branches or pull requests

2 participants