Move execute checkRow logic when XLSX file open, speed up library write file.
This commit is contained in:
parent
df8f85d6ab
commit
0dd0fba96b
12
excelize.go
12
excelize.go
|
@ -27,7 +27,7 @@ func OpenFile(filename string) (*File, error) {
|
|||
if err != nil {
|
||||
return &File{}, err
|
||||
}
|
||||
file, sheetCount, err = ReadZip(f)
|
||||
file, sheetCount, _ = ReadZip(f)
|
||||
return &File{
|
||||
XLSX: file,
|
||||
Path: filename,
|
||||
|
@ -50,7 +50,6 @@ func (f *File) SetCellInt(sheet string, axis string, value int) {
|
|||
rows := xAxis + 1
|
||||
cell := yAxis + 1
|
||||
|
||||
xlsx = checkRow(xlsx)
|
||||
xlsx = completeRow(xlsx, rows, cell)
|
||||
xlsx = completeCol(xlsx, rows, cell)
|
||||
|
||||
|
@ -79,7 +78,6 @@ func (f *File) SetCellStr(sheet string, axis string, value string) {
|
|||
rows := xAxis + 1
|
||||
cell := yAxis + 1
|
||||
|
||||
xlsx = checkRow(xlsx)
|
||||
xlsx = completeRow(xlsx, rows, cell)
|
||||
xlsx = completeCol(xlsx, rows, cell)
|
||||
|
||||
|
@ -193,7 +191,7 @@ func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
|
|||
}
|
||||
endR := getColIndex(v.C[lenCol-1].R)
|
||||
endRow := getRowIndex(v.C[lenCol-1].R)
|
||||
endCol := titleToNumber(endR)
|
||||
endCol := titleToNumber(endR) + 1
|
||||
if lenCol < endCol {
|
||||
oldRow := xlsx.SheetData.Row[k].C
|
||||
xlsx.SheetData.Row[k].C = xlsx.SheetData.Row[k].C[:0]
|
||||
|
@ -216,9 +214,9 @@ func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
|
|||
return xlsx
|
||||
}
|
||||
|
||||
// UpdateLinkedValue fix linked values within a spreadsheet are not updating.
|
||||
// This function will be remove value tag when met a cell have a linked value.
|
||||
// Reference https://social.technet.microsoft.com/Forums/office/en-US/e16bae1f-6a2c-4325-8013-e989a3479066/excel-2010-linked-cells-not-updating?forum=excel
|
||||
// UpdateLinkedValue fix linked values within a spreadsheet are not updating in
|
||||
// Office Excel 2007 and 2010. This function will be remove value tag when met a
|
||||
// cell have a linked value. Reference https://social.technet.microsoft.com/Forums/office/en-US/e16bae1f-6a2c-4325-8013-e989a3479066/excel-2010-linked-cells-not-updating?forum=excel
|
||||
//
|
||||
// Notice: after open XLSX file Excel will be update linked value and generate
|
||||
// new value and will prompt save file or not.
|
||||
|
|
|
@ -12,7 +12,7 @@ func TestExcelize(t *testing.T) {
|
|||
t.Log(err)
|
||||
}
|
||||
file.UpdateLinkedValue()
|
||||
file.SetCellInt("SHEET2", "B2", 100)
|
||||
file.SetCellInt("SHEET2", "A1", 100)
|
||||
file.SetCellStr("SHEET2", "C11", "Knowns")
|
||||
file.NewSheet(3, "TestSheet")
|
||||
file.SetCellInt("Sheet3", "A23", 10)
|
||||
|
|
6
lib.go
6
lib.go
|
@ -3,6 +3,7 @@ package excelize
|
|||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
|
@ -28,6 +29,11 @@ func ReadZipReader(r *zip.Reader) (map[string]string, int, error) {
|
|||
fileList[v.Name] = readFile(v)
|
||||
if len(v.Name) > 18 {
|
||||
if v.Name[0:19] == "xl/worksheets/sheet" {
|
||||
var xlsx xlsxWorksheet
|
||||
xml.Unmarshal([]byte(strings.Replace(fileList[v.Name], "<drawing r:id=", "<drawing rid=", -1)), &xlsx)
|
||||
xlsx = checkRow(xlsx)
|
||||
output, _ := xml.Marshal(xlsx)
|
||||
fileList[v.Name] = replaceRelationshipsID(replaceWorkSheetsRelationshipsNameSpace(string(output)))
|
||||
worksheets++
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue