gpt4 book ai didi

excel - 遍历golang中的列单元格并进行excelize

转载 作者:行者123 更新时间:2023-12-04 19:49:31 25 4
gpt4 key购买 nike

我想知道如何在golang中循环excel表格的列单元格,这是我的excel文件:
enter image description here
我出于其他原因尝试了这段代码

package main

import (
"fmt"
"github.com/xuri/excelize/v2"
)

func main() {

f, err := excelize.OpenFile("pricematching.xlsx")
if err != nil {
fmt.Println(err)
return
}

// Get all the rows in the sheet1 section.
rows, err := f.GetCellValue("sheet1", "A2")

fmt.Print(rows, "\t")

}


最佳答案

无论您的 excel 文件如何,这都是读取每个单元格的方式:

xlsxFile, error := excelize.OpenFile(filePath)
for _, sheetName := range xlsxFile.GetSheetMap() {
for rowIndex, rowValues := range xlsxFile.GetRows(sheetName) {
for columnIndex, columnValue := range rowValues {
// do what ever you want here
}
}
}

关于excel - 遍历golang中的列单元格并进行excelize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72668673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com