summaryrefslogtreecommitdiff
path: root/sheet.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2018-05-15 21:00:56 +0800
committerxuri <xuri.me@gmail.com>2018-05-15 21:00:56 +0800
commitd96440edc480976e3ec48958c68e67f7a506ad32 (patch)
tree0827d1441c2fed3acbb387b6d4c5cc8e3614cf52 /sheet.go
parent167554bfeca1bca54e36d761e2be159358736c9e (diff)
- Performance optimization 20% faster, 14% memory savings on set cell values;
- Using the canonical syntax in issue template and contributing guide; - go test has been updated
Diffstat (limited to 'sheet.go')
-rw-r--r--sheet.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/sheet.go b/sheet.go
index 10a0fdb..cb3bba2 100644
--- a/sheet.go
+++ b/sheet.go
@@ -94,13 +94,15 @@ func (f *File) worksheetWriter() {
// trimCell provides function to trim blank cells which created by completeCol.
func trimCell(column []xlsxC) []xlsxC {
- col := []xlsxC{}
+ col := make([]xlsxC, len(column))
+ i := 0
for _, c := range column {
if c.S != 0 || c.V != "" || c.F != nil || c.T != "" {
- col = append(col, c)
+ col[i] = c
+ i++
}
}
- return col
+ return col[0:i]
}
// Read and update property of contents type of XLSX.
@@ -641,8 +643,16 @@ func (f *File) GetSheetVisible(name string) bool {
// trimSheetName provides function to trim invaild characters by given worksheet
// name.
func trimSheetName(name string) string {
- r := strings.NewReplacer(":", "", "\\", "", "/", "", "?", "", "*", "", "[", "", "]", "")
- name = r.Replace(name)
+ r := []rune{}
+ for _, v := range []rune(name) {
+ switch v {
+ case 58, 92, 47, 63, 42, 91, 93: // replace :\/?*[]
+ continue
+ default:
+ r = append(r, v)
+ }
+ }
+ name = string(r)
if utf8.RuneCountInString(name) > 31 {
name = string([]rune(name)[0:31])
}