forked from p30928647/excelize
Conut and trim sheet name in UTF-8
This commit is contained in:
parent
845e339755
commit
02728de4d2
11
sheet.go
11
sheet.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewSheet provides function to create a new sheet by given index, when
|
// 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
|
// setWorkbook update workbook property of XLSX. Maximum 31 characters are
|
||||||
// allowed in sheet title.
|
// allowed in sheet title.
|
||||||
func (f *File) setWorkbook(name string, rid int) {
|
func (f *File) setWorkbook(name string, rid int) {
|
||||||
r := strings.NewReplacer(":", "", "\\", "", "/", "", "?", "", "*", "", "[", "", "]", "")
|
name = trimSheetName(name)
|
||||||
name = r.Replace(name)
|
|
||||||
if len(name) > 31 {
|
|
||||||
name = name[0:31]
|
|
||||||
}
|
|
||||||
content := f.workbookReader()
|
content := f.workbookReader()
|
||||||
content.Sheets.Sheet = append(content.Sheets.Sheet, xlsxSheet{
|
content.Sheets.Sheet = append(content.Sheets.Sheet, xlsxSheet{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -646,8 +643,8 @@ func (f *File) GetSheetVisible(name string) bool {
|
||||||
func trimSheetName(name string) string {
|
func trimSheetName(name string) string {
|
||||||
r := strings.NewReplacer(":", "", "\\", "", "/", "", "?", "", "*", "", "[", "", "]", "")
|
r := strings.NewReplacer(":", "", "\\", "", "/", "", "?", "", "*", "", "[", "", "]", "")
|
||||||
name = r.Replace(name)
|
name = r.Replace(name)
|
||||||
if len(name) > 31 {
|
if utf8.RuneCountInString(name) > 31 {
|
||||||
name = name[0:31]
|
name = string([]rune(name)[0:31])
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue