This closes #1712, reduce memory consumption (#1713)

This commit is contained in:
Marko Krstic 2023-11-07 01:46:01 +01:00 committed by GitHub
parent fe639faa45
commit 6cc1a547ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 11 deletions

View File

@ -179,35 +179,38 @@ func (f *File) workSheetWriter() {
func trimRow(sheetData *xlsxSheetData) []xlsxRow {
var (
row xlsxRow
rows []xlsxRow
i int
)
for k, v := range sheetData.Row {
for k := range sheetData.Row {
row = sheetData.Row[k]
if row.C = trimCell(v.C); len(row.C) != 0 || row.hasAttr() {
rows = append(rows, row)
if row = trimCell(row); len(row.C) != 0 || row.hasAttr() {
sheetData.Row[i] = row
}
i++
}
return rows
return sheetData.Row[:i]
}
// trimCell provides a function to trim blank cells which created by fillColumns.
func trimCell(column []xlsxC) []xlsxC {
func trimCell(row xlsxRow) xlsxRow {
column := row.C
rowFull := true
for i := range column {
rowFull = column[i].hasValue() && rowFull
}
if rowFull {
return column
return row
}
col := make([]xlsxC, len(column))
i := 0
for _, c := range column {
if c.hasValue() {
col[i] = c
row.C[i] = c
i++
}
}
return col[:i]
row.C = row.C[:i]
return row
}
// setContentTypes provides a function to read and update property of contents