summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2016-09-07 20:09:02 +0800
committerRi Xu <xuri.me@gmail.com>2016-09-07 20:09:02 +0800
commit0dd0fba96b8a33eb5fd365131bfc4a2361a9fe3f (patch)
treed55489640f7643bd6026e223a996f347d250652b
parentdf8f85d6abdebba567766484705134f30bf5f847 (diff)
Move execute checkRow logic when XLSX file open, speed up library write file.
-rw-r--r--excelize.go12
-rw-r--r--excelize_test.go2
-rw-r--r--lib.go6
3 files changed, 12 insertions, 8 deletions
diff --git a/excelize.go b/excelize.go
index 15710db..79f7534 100644
--- a/excelize.go
+++ b/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.
diff --git a/excelize_test.go b/excelize_test.go
index 7af1991..7d37a6a 100644
--- a/excelize_test.go
+++ b/excelize_test.go
@@ -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)
diff --git a/lib.go b/lib.go
index 0fe6870..1274b0f 100644
--- a/lib.go
+++ b/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++
}
}