Closed lengrongfu closed 5 years ago
What sort of limitations are you running into with a million rows? Are you running out of memory?
写了N久都没有写进去。
@lengrongfu csv, if dificute to write to excel?~
请问怎么遍历二维数组, 写入Excel呀, 我看api都是要指定单元格写数据, 如 "A2", "B3".
@Nisus-Liu like this?
func axis(rowN, colN int) string {
return excelize.ToAlphaString(colN) + strconv.Itoa(rowN+1)
}
var sheet string
for rowN :=range data{
for colNum :=range data[rowNum]{
xlsx.SetCellValue(sheet, axis(rowNum, colNum), data[rowNum][colNum])
}
}
it is comfortable for me
use data slice as the third parameters of SetSheetRow
for k, v := range arrs {
f.SetSheetRow("sheet1", fmt.Sprint("A", k+1), &[]string{v.field1,v.field2,v.field3,....v.fieldN})
}
SetSheetRow()只有这一种方式吗?有木有一次插入1000行、5000行、、、
Please using stream writer for generating a new worksheet with huge amounts of data.
ToAlphaString
ToAlphaString 在 v2.0.0 API已经删除
Please using ColumnNumberToName
instead of ToAlphaString
.
work for v2.6.1
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
"strconv"
)
func axis(rowN, colN int) string {
colName, err := excelize.ColumnNumberToName(colN + 1)
if err != nil {
panic(err)
}
return colName + strconv.Itoa(rowN+1)
}
func Run(datas [][]string) {
f := excelize.NewFile()
sheetName := "ocr"
index := f.NewSheet(sheetName)
for rowN := range datas {
for colNum := range datas[rowN] {
if err := f.SetCellValue(sheetName, axis(rowN, colNum), datas[rowN][colNum]); err != nil {
panic(err)
}
}
}
f.SetActiveSheet(index)
if err := f.SaveAs("my.xlsx"); err != nil {
fmt.Println(err)
}
}
a usage from https://github.com/qax-os/excelize/issues/364#issuecomment-478312887
//axis(1, 1) return "A1"
func axis(rowN, colN int) string {
return excelize.ToAlphaString(colN-1) + strconv.Itoa(rowN)
}
如果遇到一个需要写入100万行的数据,如何高效的写入?