diff options
author | xuri <xuri.me@gmail.com> | 2018-07-17 15:28:22 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2018-07-17 15:28:22 +0800 |
commit | a3571ee39bec82d15d9a183aed7f7db39e0a160f (patch) | |
tree | 92e5961496640d711006768f71542dae93ab89ea | |
parent | 79dfe1c3070b3c4af14a40acaa5bd8cb477acd3e (diff) |
Bugfix: create worksheet cause file issue. Relate issue #249.
-rw-r--r-- | comment.go | 2 | ||||
-rw-r--r-- | excelize_test.go | 4 | ||||
-rw-r--r-- | sheet.go | 10 |
3 files changed, 10 insertions, 6 deletions
@@ -15,7 +15,7 @@ func parseFormatCommentsSet(formatSet string) (*formatComment, error) { Author: "Author:", Text: " ", } - err := json.Unmarshal(parseFormatSet(formatSet), &format) + err := json.Unmarshal([]byte(formatSet), &format) return &format, err } diff --git a/excelize_test.go b/excelize_test.go index 94732fe..c9a87d0 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -771,10 +771,6 @@ func TestAddTable(t *testing.T) { if err != nil { t.Error(err) } - err = xlsx.AddTable("Sheet2", "A2", "B5", ``) - if err != nil { - t.Log(err) - } err = xlsx.AddTable("Sheet2", "A2", "B5", `{"table_name":"table","table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`) if err != nil { t.Error(err) @@ -132,9 +132,17 @@ func (f *File) setSheet(index int, name string) { // allowed in sheet title. func (f *File) setWorkbook(name string, rid int) { content := f.workbookReader() + rID := 0 + for _, v := range content.Sheets.Sheet { + t, _ := strconv.Atoi(v.SheetID) + if t > rID { + rID = t + } + } + rID++ content.Sheets.Sheet = append(content.Sheets.Sheet, xlsxSheet{ Name: trimSheetName(name), - SheetID: strconv.Itoa(rid), + SheetID: strconv.Itoa(rID), ID: "rId" + strconv.Itoa(rid), }) } |