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

CalcCellValue returns incorrect results in some case #1807

Closed
BigtigerGG opened this issue Feb 4, 2024 · 5 comments · Fixed by #1810
Closed

CalcCellValue returns incorrect results in some case #1807

BigtigerGG opened this issue Feb 4, 2024 · 5 comments · Fixed by #1810
Labels
bug Something isn't working

Comments

@BigtigerGG
Copy link

我的Excel文件有两个工作表,分别为:

  • Sheet1
  • Sheet2

Sheet2中有一列的值使用VLOOKUP计算,公式内容为:VLOOKUP(C4,'Sheet1'!A$2:B$200,2,0),目的是为了在Sheet1的 A$2:B$200范围内中查找Sheet2 C4单元格值,并返回Sheet1对应第二列的值

但是实际上CalcCellValue返回了 空字符串 且没有任何报错,想请教下这个问题该如何解决

@xuri
Copy link
Member

xuri commented Feb 4, 2024

Thanks for your issue. Which version of the Excelize library are you using? Could you follow the issue template and show us a complete, standalone example program or reproducible demo?

@xuri xuri added the needs more info This issue can't reproduce, need more info label Feb 4, 2024
@BigtigerGG
Copy link
Author

BigtigerGG commented Feb 4, 2024

Thanks for your issue. Which version of the Excelize library are you using? Could you follow the issue template and show us a complete, standalone example program or reproducible demo?

感谢回复🙏!
excelize版本:v2.8.0
Description
CalcCellValue 似乎不能在跨工作表总计算公式值

Steps to reproduce the issue:

  1. 示例文件:demo.xlsx
  2. 使用go1.18编写如下测试代码
func getExcel() (*excelize.File, error) {
	f, err := excelize.OpenFile("demo.xlsx")
	if err != nil {
		fmt.Println(err)
		return nil, err
	}
	defer func() {
		if err := f.Close(); err != nil {
			fmt.Println(err)
		}
	}()
	return f, nil
}

func testCalc(_ context.Context) error {
	f, err := getExcel()
	if err != nil {
		return err
	}
	const (
		sheet1 = "Sheet1"
		sheet2 = "Sheet2"
	)

	// 打印公式
	formula, err1 := f.GetCellFormula(sheet2, "B1")
	fmt.Printf("公式:%s 错误:%s \n", formula, err1)

	// 计算公式
	calVal, err2 := f.CalcCellValue(sheet2, "B1")
	fmt.Printf("公式结果:%s 错误: %s \n", calVal, err2)
	return nil
}

Describe the results you received:

公式:VLOOKUP(A1,'Sheet1'!A$1:B200,2,0) 错误:nil
公式结果: 错误: nil

Describe the results you expected:
从代码返回结果来看,这个方法返回了空字符串,预期应该返回 Bar1
image

Output of go version:

go version go1.18.10 darwin/arm64

Excelize version or commit ID:

v2.8.0

Environment details (OS, Microsoft Excel™ version, physical, etc.):
示例文件:
demo.xlsx

@BigtigerGG BigtigerGG changed the title CalcCellValue 不能在跨工作表总计算公式值 CalcCellValue 不能跨工作表计算公式值 Feb 4, 2024
@BigtigerGG
Copy link
Author

@xuri 完整的复现路径如上所示🙏🙏

@xuri xuri added bug Something isn't working and removed needs more info This issue can't reproduce, need more info labels Feb 4, 2024
@xuri xuri changed the title CalcCellValue 不能跨工作表计算公式值 CalcCellValue returns incorrect results in some case Feb 4, 2024
taitaking pushed a commit to taitaking/excelize that referenced this issue Feb 4, 2024
@xuri xuri linked a pull request Feb 4, 2024 that will close this issue
10 tasks
@xuri xuri closed this as completed in #1810 Feb 4, 2024
xuri pushed a commit that referenced this issue Feb 4, 2024
@xuri
Copy link
Member

xuri commented Feb 4, 2024

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.

@BigtigerGG
Copy link
Author

感谢🙏

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
None yet
Development

Successfully merging a pull request may close this issue.

2 participants