杰出pkg.go golang

发布于 2025-02-05 21:09:54 字数 776 浏览 0 评论 0原文

我正在使用Excelize包装来操纵Excel文件。我对setCellformula func有问题,它不应用公式。我粘贴了一个基本的例子,我只是在尝试

func main() {

    f := excelize.NewFile()

    f.SetCellValue("Sheet1", "A1", "ID")
    f.SetCellValue("Sheet1", "B1", "Nome")
    f.SetCellValue("Sheet1", "D1", "Cognome")
    f.SetCellValue("Sheet1", "C1", "Email")
    f.SetCellValue("Sheet1", "D1", "IDENTITY_CARD_EXPIRE_DATE")
    f.SetCellValue("Sheet1", "E1", "TOTAL")

    f.SetCellValue("Sheet1", "E2", "1")
    f.SetCellValue("Sheet1", "E3", "5")
    f.SetCellValue("Sheet1", "E4", "10")

    //formula
    f.SetCellFormula("Sheet1", "E6", "=SUBTOTALE(9;E2:E8)")

    f.SetColWidth("Sheet1", "A", "D", 30)
    if err := f.SaveAs("Personal_Data.xlsx"); err != nil {
        log.Fatal(err)
    }
}

谢谢大家

I'm using the excelize packaging to manipulate excel files. I am having a problem with the setcellformula func, it does not apply the formula. I paste a basic example, where I was just trying

func main() {

    f := excelize.NewFile()

    f.SetCellValue("Sheet1", "A1", "ID")
    f.SetCellValue("Sheet1", "B1", "Nome")
    f.SetCellValue("Sheet1", "D1", "Cognome")
    f.SetCellValue("Sheet1", "C1", "Email")
    f.SetCellValue("Sheet1", "D1", "IDENTITY_CARD_EXPIRE_DATE")
    f.SetCellValue("Sheet1", "E1", "TOTAL")

    f.SetCellValue("Sheet1", "E2", "1")
    f.SetCellValue("Sheet1", "E3", "5")
    f.SetCellValue("Sheet1", "E4", "10")

    //formula
    f.SetCellFormula("Sheet1", "E6", "=SUBTOTALE(9;E2:E8)")

    f.SetColWidth("Sheet1", "A", "D", 30)
    if err := f.SaveAs("Personal_Data.xlsx"); err != nil {
        log.Fatal(err)
    }
}

Thank you all

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶茶白久 2025-02-12 21:09:55

您的代码有三个问题:

首先,将数字值添加为字符串。您应该使用整数作为
第三参数:第二

f.SetCellValue("Sheet1", "E2", 1)
f.SetCellValue("Sheet1", "E3", 5)
f.SetCellValue("Sheet1", "E4", 10)

个参数,在公式中,您不应添加相等的符号,必须使用逗号而不是semicolon,并且必须使用英语函数名称:

f.SetCellFormula("Sheet1", "E6", "SUBTOTAL(9,E2:E4)")

此外,您在公式中具有圆形参考,因为它在E6单元格中,但是范围是您的示例中的e2:e8,其中包含e6。因此,您也必须改变它。

You have three problems with your code:

First, you add the numeric values as strings. You should use integers as the
third parameter:

f.SetCellValue("Sheet1", "E2", 1)
f.SetCellValue("Sheet1", "E3", 5)
f.SetCellValue("Sheet1", "E4", 10)

Second, in the formula, you shouldn't add equal sign, you must use comma instead of semicolon and you must use the english function name:

f.SetCellFormula("Sheet1", "E6", "SUBTOTAL(9,E2:E4)")

Furthermore you have a circular reference in your formula, because it is in E6 cell, but the range is E2:E8 in you example, which has E6 in it. So you have to change that too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文