summaryrefslogtreecommitdiff
path: root/excelize.go
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2016-09-04 19:25:31 +0800
committerRi Xu <xuri.me@gmail.com>2016-09-04 19:25:31 +0800
commit9c3a24d5c369216ec5e1c292dd6547f7e263d23f (patch)
treeb42d3c7aea1328c1b8a0cabb5e0ecaf7a40e3ef2 /excelize.go
parent78e79347b650baffca03ee61dffff59e978a79e2 (diff)
xml marshal without indent and use buffer in string concatenation.
Diffstat (limited to 'excelize.go')
-rw-r--r--excelize.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/excelize.go b/excelize.go
index 5ac7660..6da8639 100644
--- a/excelize.go
+++ b/excelize.go
@@ -2,6 +2,7 @@ package excelize
import (
"archive/zip"
+ "bytes"
"encoding/xml"
"fmt"
"strconv"
@@ -48,7 +49,7 @@ func SetCellInt(file []FileList, sheet string, axis string, value int) []FileLis
xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value)
- output, err := xml.MarshalIndent(xlsx, "", "")
+ output, err := xml.Marshal(xlsx)
if err != nil {
fmt.Println(err)
}
@@ -78,7 +79,7 @@ func SetCellStr(file []FileList, sheet string, axis string, value string) []File
xlsx.SheetData.Row[xAxis].C[yAxis].T = "str"
xlsx.SheetData.Row[xAxis].C[yAxis].V = value
- output, err := xml.MarshalIndent(xlsx, "", "")
+ output, err := xml.Marshal(xlsx)
if err != nil {
fmt.Println(err)
}
@@ -95,13 +96,17 @@ func completeCol(xlsx xlsxWorksheet, row int, cell int) xlsxWorksheet {
})
}
}
+ buffer := bytes.Buffer{}
for k, v := range xlsx.SheetData.Row {
if len(v.C) < cell {
start := len(v.C)
for iii := start; iii < cell; iii++ {
+ buffer.WriteString(toAlphaString(iii + 1))
+ buffer.WriteString(strconv.Itoa(k + 1))
xlsx.SheetData.Row[k].C = append(xlsx.SheetData.Row[k].C, xlsxC{
- R: toAlphaString(iii+1) + strconv.Itoa(k+1),
+ R: buffer.String(),
})
+ buffer.Reset()
}
}
}
@@ -116,14 +121,17 @@ func completeRow(xlsx xlsxWorksheet, row int, cell int) xlsxWorksheet {
R: i + 1,
})
}
-
+ buffer := bytes.Buffer{}
for ii := 0; ii < row; ii++ {
start := len(xlsx.SheetData.Row[ii].C)
if start == 0 {
for iii := start; iii < cell; iii++ {
+ buffer.WriteString(toAlphaString(iii + 1))
+ buffer.WriteString(strconv.Itoa(ii + 1))
xlsx.SheetData.Row[ii].C = append(xlsx.SheetData.Row[ii].C, xlsxC{
- R: toAlphaString(iii+1) + strconv.Itoa(ii+1),
+ R: buffer.String(),
})
+ buffer.Reset()
}
}
}
@@ -170,6 +178,7 @@ func replaceWorkSheetsRelationshipsNameSpace(workbookMarshal string) string {
// </row>
//
func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
+ buffer := bytes.Buffer{}
for k, v := range xlsx.SheetData.Row {
lenCol := len(v.C)
if lenCol < 1 {
@@ -183,10 +192,12 @@ func checkRow(xlsx xlsxWorksheet) xlsxWorksheet {
xlsx.SheetData.Row[k].C = xlsx.SheetData.Row[k].C[:0]
tmp := []xlsxC{}
for i := 0; i <= endCol; i++ {
- fixAxis := toAlphaString(i+1) + strconv.Itoa(endRow)
+ buffer.WriteString(toAlphaString(i + 1))
+ buffer.WriteString(strconv.Itoa(endRow))
tmp = append(tmp, xlsxC{
- R: fixAxis,
+ R: buffer.String(),
})
+ buffer.Reset()
}
xlsx.SheetData.Row[k].C = tmp
for _, y := range oldRow {