Browse Source

Further improve read performance

Instead of re-encoding the full sheet to change the namespaces
in the encoded bytes, read the sheet again and do the byte
replacements there.

In this case, file access ends up being more performant than
marshaling the sheet back to XML.

In the SharedStrings test, ensure the strings are actually read.

Fix #439
Harris 6 years ago
parent
commit
e07581e980
2 changed files with 7 additions and 3 deletions
  1. 5 1
      excelize_test.go
  2. 2 2
      rows.go

+ 5 - 1
excelize_test.go

@@ -1003,7 +1003,11 @@ func TestSharedStrings(t *testing.T) {
 	if !assert.NoError(t, err) {
 	if !assert.NoError(t, err) {
 		t.FailNow()
 		t.FailNow()
 	}
 	}
-	f.GetRows("Sheet1")
+	rows, err := f.GetRows("Sheet1")
+	if !assert.NoError(t, err) {
+		t.FailNow()
+	}
+	assert.Equal(t, "A", rows[0][0])
 }
 }
 
 
 func TestSetSheetRow(t *testing.T) {
 func TestSetSheetRow(t *testing.T) {

+ 2 - 2
rows.go

@@ -112,8 +112,8 @@ func (f *File) Rows(sheet string) (*Rows, error) {
 		return nil, ErrSheetNotExist{sheet}
 		return nil, ErrSheetNotExist{sheet}
 	}
 	}
 	if xlsx != nil {
 	if xlsx != nil {
-		output, _ := xml.Marshal(f.Sheet[name])
-		f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpaceBytes(output))
+		data := f.readXML(name)
+		f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpaceBytes(namespaceStrictToTransitional(data)))
 	}
 	}
 	return &Rows{
 	return &Rows{
 		f:    f,
 		f:    f,