diff options
author | Ri Xu <xuri.me@gmail.com> | 2017-08-13 14:35:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-13 14:35:27 +0800 |
commit | 58e2caff33906df86cd51446acb74be833aee140 (patch) | |
tree | ffaba6467f630e6c82f7deba8867ac88b0226599 | |
parent | 845e339755ce6f59484e05e977ecef1fdb3c5ef8 (diff) | |
parent | 02728de4d2688f8384e1ae85b7a2a1b912e77d50 (diff) |
Merge pull request #103 from takayuki/trim-sheet-name-as-rune
Conut and trim sheet name in UTF-8
-rw-r--r-- | sheet.go | 11 |
1 files changed, 4 insertions, 7 deletions
@@ -9,6 +9,7 @@ import ( "path" "strconv" "strings" + "unicode/utf8" ) // NewSheet provides function to create a new sheet by given index, when @@ -121,11 +122,7 @@ func (f *File) setSheet(index int) { // setWorkbook update workbook property of XLSX. Maximum 31 characters are // allowed in sheet title. func (f *File) setWorkbook(name string, rid int) { - r := strings.NewReplacer(":", "", "\\", "", "/", "", "?", "", "*", "", "[", "", "]", "") - name = r.Replace(name) - if len(name) > 31 { - name = name[0:31] - } + name = trimSheetName(name) content := f.workbookReader() content.Sheets.Sheet = append(content.Sheets.Sheet, xlsxSheet{ Name: name, @@ -646,8 +643,8 @@ func (f *File) GetSheetVisible(name string) bool { func trimSheetName(name string) string { r := strings.NewReplacer(":", "", "\\", "", "/", "", "?", "", "*", "", "[", "", "]", "") name = r.Replace(name) - if len(name) > 31 { - name = name[0:31] + if utf8.RuneCountInString(name) > 31 { + name = string([]rune(name)[0:31]) } return name } |