Browse Source

- Add error return value for functions: `AddChart()`, `AddComment()`, `AddPicture()`, `AddShape()`, `AddTable()` and `SetConditionalFormat()`
- go test has been updated

xuri 7 years ago
parent
commit
9e463b4614
11 changed files with 117 additions and 72 deletions
  1. 10 6
      chart.go
  2. 11 7
      comment.go
  3. 1 1
      excelize.go
  4. 24 4
      excelize_test.go
  5. 1 1
      lib.go
  6. 16 13
      picture.go
  7. 7 7
      rows.go
  8. 9 5
      shape.go
  9. 16 13
      sheet.go
  10. 7 4
      styles.go
  11. 15 11
      table.go

+ 10 - 6
chart.go

@@ -192,7 +192,7 @@ var (
 
 
 // parseFormatChartSet provides function to parse the format settings of the
 // parseFormatChartSet provides function to parse the format settings of the
 // chart with default value.
 // chart with default value.
-func parseFormatChartSet(formatSet string) *formatChart {
+func parseFormatChartSet(formatSet string) (*formatChart, error) {
 	format := formatChart{
 	format := formatChart{
 		Dimension: formatChartDimension{
 		Dimension: formatChartDimension{
 			Width:  480,
 			Width:  480,
@@ -216,8 +216,8 @@ func parseFormatChartSet(formatSet string) *formatChart {
 		},
 		},
 		ShowBlanksAs: "gap",
 		ShowBlanksAs: "gap",
 	}
 	}
-	json.Unmarshal([]byte(formatSet), &format)
-	return &format
+	err := json.Unmarshal([]byte(formatSet), &format)
+	return &format, err
 }
 }
 
 
 // AddChart provides the method to add chart in a sheet by given chart format
 // AddChart provides the method to add chart in a sheet by given chart format
@@ -357,8 +357,11 @@ func parseFormatChartSet(formatSet string) *formatChart {
 //
 //
 // Set chart size by dimension property. The dimension property is optional. The default width is 480, and height is 290.
 // Set chart size by dimension property. The dimension property is optional. The default width is 480, and height is 290.
 //
 //
-func (f *File) AddChart(sheet, cell, format string) {
-	formatSet := parseFormatChartSet(format)
+func (f *File) AddChart(sheet, cell, format string) error {
+	formatSet, err := parseFormatChartSet(format)
+	if err != nil {
+		return err
+	}
 	// Read sheet data.
 	// Read sheet data.
 	xlsx := f.workSheetReader(sheet)
 	xlsx := f.workSheetReader(sheet)
 	// Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
 	// Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
@@ -371,6 +374,7 @@ func (f *File) AddChart(sheet, cell, format string) {
 	f.addChart(formatSet)
 	f.addChart(formatSet)
 	f.addContentTypePart(chartID, "chart")
 	f.addContentTypePart(chartID, "chart")
 	f.addContentTypePart(drawingID, "drawings")
 	f.addContentTypePart(drawingID, "drawings")
+	return err
 }
 }
 
 
 // countCharts provides function to get chart files count storage in the
 // countCharts provides function to get chart files count storage in the
@@ -1082,7 +1086,7 @@ func (f *File) drawingParser(drawingXML string, content *xlsxWsDr) int {
 	_, ok := f.XLSX[drawingXML]
 	_, ok := f.XLSX[drawingXML]
 	if ok { // Append Model
 	if ok { // Append Model
 		decodeWsDr := decodeWsDr{}
 		decodeWsDr := decodeWsDr{}
-		xml.Unmarshal([]byte(f.readXML(drawingXML)), &decodeWsDr)
+		_ = xml.Unmarshal([]byte(f.readXML(drawingXML)), &decodeWsDr)
 		content.R = decodeWsDr.R
 		content.R = decodeWsDr.R
 		cNvPrID = len(decodeWsDr.OneCellAnchor) + len(decodeWsDr.TwoCellAnchor) + 1
 		cNvPrID = len(decodeWsDr.OneCellAnchor) + len(decodeWsDr.TwoCellAnchor) + 1
 		for _, v := range decodeWsDr.OneCellAnchor {
 		for _, v := range decodeWsDr.OneCellAnchor {

+ 11 - 7
comment.go

@@ -9,13 +9,13 @@ import (
 
 
 // parseFormatCommentsSet provides function to parse the format settings of the
 // parseFormatCommentsSet provides function to parse the format settings of the
 // comment with default value.
 // comment with default value.
-func parseFormatCommentsSet(formatSet string) *formatComment {
+func parseFormatCommentsSet(formatSet string) (*formatComment, error) {
 	format := formatComment{
 	format := formatComment{
 		Author: "Author:",
 		Author: "Author:",
 		Text:   " ",
 		Text:   " ",
 	}
 	}
-	json.Unmarshal([]byte(formatSet), &format)
-	return &format
+	err := json.Unmarshal([]byte(formatSet), &format)
+	return &format, err
 }
 }
 
 
 // AddComment provides the method to add comment in a sheet by given worksheet
 // AddComment provides the method to add comment in a sheet by given worksheet
@@ -25,8 +25,11 @@ func parseFormatCommentsSet(formatSet string) *formatComment {
 //
 //
 //    xlsx.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`)
 //    xlsx.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`)
 //
 //
-func (f *File) AddComment(sheet, cell, format string) {
-	formatSet := parseFormatCommentsSet(format)
+func (f *File) AddComment(sheet, cell, format string) error {
+	formatSet, err := parseFormatCommentsSet(format)
+	if err != nil {
+		return err
+	}
 	// Read sheet data.
 	// Read sheet data.
 	xlsx := f.workSheetReader(sheet)
 	xlsx := f.workSheetReader(sheet)
 	commentID := f.countComments() + 1
 	commentID := f.countComments() + 1
@@ -48,6 +51,7 @@ func (f *File) AddComment(sheet, cell, format string) {
 	f.addComment(commentsXML, cell, formatSet)
 	f.addComment(commentsXML, cell, formatSet)
 	f.addDrawingVML(commentID, drawingVML, cell)
 	f.addDrawingVML(commentID, drawingVML, cell)
 	f.addContentTypePart(commentID, "comments")
 	f.addContentTypePart(commentID, "comments")
+	return err
 }
 }
 
 
 // addDrawingVML provides function to create comment as
 // addDrawingVML provides function to create comment as
@@ -127,7 +131,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string) {
 	c, ok := f.XLSX[drawingVML]
 	c, ok := f.XLSX[drawingVML]
 	if ok {
 	if ok {
 		d := decodeVmlDrawing{}
 		d := decodeVmlDrawing{}
-		xml.Unmarshal([]byte(c), &d)
+		_ = xml.Unmarshal([]byte(c), &d)
 		for _, v := range d.Shape {
 		for _, v := range d.Shape {
 			s := xlsxShape{
 			s := xlsxShape{
 				ID:          "_x0000_s1025",
 				ID:          "_x0000_s1025",
@@ -197,7 +201,7 @@ func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
 	c, ok := f.XLSX[commentsXML]
 	c, ok := f.XLSX[commentsXML]
 	if ok {
 	if ok {
 		d := xlsxComments{}
 		d := xlsxComments{}
-		xml.Unmarshal([]byte(c), &d)
+		_ = xml.Unmarshal([]byte(c), &d)
 		comments.CommentList.Comment = append(comments.CommentList.Comment, d.CommentList.Comment...)
 		comments.CommentList.Comment = append(comments.CommentList.Comment, d.CommentList.Comment...)
 	}
 	}
 	comments.CommentList.Comment = append(comments.CommentList.Comment, cmt)
 	comments.CommentList.Comment = append(comments.CommentList.Comment, cmt)

+ 1 - 1
excelize.go

@@ -88,7 +88,7 @@ func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
 	}
 	}
 	if f.Sheet[name] == nil {
 	if f.Sheet[name] == nil {
 		var xlsx xlsxWorksheet
 		var xlsx xlsxWorksheet
-		xml.Unmarshal(f.readXML(name), &xlsx)
+		_ = xml.Unmarshal(f.readXML(name), &xlsx)
 		if f.checked == nil {
 		if f.checked == nil {
 			f.checked = make(map[string]bool)
 			f.checked = make(map[string]bool)
 		}
 		}

+ 24 - 4
excelize_test.go

@@ -211,9 +211,10 @@ func TestNewFile(t *testing.T) {
 	if err != nil {
 	if err != nil {
 		t.Error(err)
 		t.Error(err)
 	}
 	}
+	// Test add picture to worksheet with invalid formatset
 	err = xlsx.AddPicture("Sheet1", "C2", "./test/images/excel.png", "")
 	err = xlsx.AddPicture("Sheet1", "C2", "./test/images/excel.png", "")
 	if err != nil {
 	if err != nil {
-		t.Error(err)
+		t.Log(err)
 	}
 	}
 	err = xlsx.SaveAs("./test/Book3.xlsx")
 	err = xlsx.SaveAs("./test/Book3.xlsx")
 	if err != nil {
 	if err != nil {
@@ -651,6 +652,7 @@ func TestSetDeleteSheet(t *testing.T) {
 		t.Error(err)
 		t.Error(err)
 	}
 	}
 	xlsx.DeleteSheet("Sheet1")
 	xlsx.DeleteSheet("Sheet1")
+	xlsx.AddComment("Sheet1", "A1", "")
 	xlsx.AddComment("Sheet1", "A1", `{"author":"Excelize: ","text":"This is a comment."}`)
 	xlsx.AddComment("Sheet1", "A1", `{"author":"Excelize: ","text":"This is a comment."}`)
 	err = xlsx.SaveAs("./test/Book_delete_sheet.xlsx")
 	err = xlsx.SaveAs("./test/Book_delete_sheet.xlsx")
 	if err != nil {
 	if err != nil {
@@ -765,9 +767,22 @@ func TestAddTable(t *testing.T) {
 	if err != nil {
 	if err != nil {
 		t.Error(err)
 		t.Error(err)
 	}
 	}
-	xlsx.AddTable("Sheet1", "B26", "A21", ``)
-	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}`)
-	xlsx.AddTable("Sheet2", "F1", "F1", `{"table_style":"TableStyleMedium8"}`)
+	err = xlsx.AddTable("Sheet1", "B26", "A21", `{}`)
+	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)
+	}
+	err = xlsx.AddTable("Sheet2", "F1", "F1", `{"table_style":"TableStyleMedium8"}`)
+	if err != nil {
+		t.Error(err)
+	}
 	err = xlsx.Save()
 	err = xlsx.Save()
 	if err != nil {
 	if err != nil {
 		t.Error(err)
 		t.Error(err)
@@ -783,6 +798,7 @@ func TestAddShape(t *testing.T) {
 	xlsx.AddShape("Sheet1", "B30", `{"type":"rect","paragraph":[{"text":"Rectangle"},{}]}`)
 	xlsx.AddShape("Sheet1", "B30", `{"type":"rect","paragraph":[{"text":"Rectangle"},{}]}`)
 	xlsx.AddShape("Sheet1", "C30", `{"type":"rect","paragraph":[]}`)
 	xlsx.AddShape("Sheet1", "C30", `{"type":"rect","paragraph":[]}`)
 	xlsx.AddShape("Sheet3", "H1", `{"type":"ellipseRibbon", "color":{"line":"#4286f4","fill":"#8eb9ff"}, "paragraph":[{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"single"}}], "height": 90}`)
 	xlsx.AddShape("Sheet3", "H1", `{"type":"ellipseRibbon", "color":{"line":"#4286f4","fill":"#8eb9ff"}, "paragraph":[{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"single"}}], "height": 90}`)
+	xlsx.AddShape("Sheet3", "H1", "")
 	err = xlsx.Save()
 	err = xlsx.Save()
 	if err != nil {
 	if err != nil {
 		t.Error(err)
 		t.Error(err)
@@ -846,6 +862,7 @@ func TestAddChart(t *testing.T) {
 	for k, v := range values {
 	for k, v := range values {
 		xlsx.SetCellValue("Sheet1", k, v)
 		xlsx.SetCellValue("Sheet1", k, v)
 	}
 	}
+	xlsx.AddChart("Sheet1", "P1", "")
 	xlsx.AddChart("Sheet1", "P1", `{"type":"col","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"left","show_legend_key":false},"title":{"name":"Fruit 2D Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero"}`)
 	xlsx.AddChart("Sheet1", "P1", `{"type":"col","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"left","show_legend_key":false},"title":{"name":"Fruit 2D Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero"}`)
 	xlsx.AddChart("Sheet1", "X1", `{"type":"colStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"left","show_legend_key":false},"title":{"name":"Fruit 2D Stacked Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero"}`)
 	xlsx.AddChart("Sheet1", "X1", `{"type":"colStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"left","show_legend_key":false},"title":{"name":"Fruit 2D Stacked Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero"}`)
 	xlsx.AddChart("Sheet1", "P16", `{"type":"colPercentStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"left","show_legend_key":false},"title":{"name":"Fruit 100% Stacked Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero"}`)
 	xlsx.AddChart("Sheet1", "P16", `{"type":"colPercentStacked","series":[{"name":"Sheet1!$A$30","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$30:$D$30"},{"name":"Sheet1!$A$31","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$31:$D$31"},{"name":"Sheet1!$A$32","categories":"Sheet1!$B$29:$D$29","values":"Sheet1!$B$32:$D$32"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"left","show_legend_key":false},"title":{"name":"Fruit 100% Stacked Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero"}`)
@@ -937,6 +954,7 @@ func TestSetPane(t *testing.T) {
 	xlsx.SetPanes("Panes 3", `{"freeze":false,"split":true,"x_split":3270,"y_split":1800,"top_left_cell":"N57","active_pane":"bottomLeft","panes":[{"sqref":"I36","active_cell":"I36"},{"sqref":"G33","active_cell":"G33","pane":"topRight"},{"sqref":"J60","active_cell":"J60","pane":"bottomLeft"},{"sqref":"O60","active_cell":"O60","pane":"bottomRight"}]}`)
 	xlsx.SetPanes("Panes 3", `{"freeze":false,"split":true,"x_split":3270,"y_split":1800,"top_left_cell":"N57","active_pane":"bottomLeft","panes":[{"sqref":"I36","active_cell":"I36"},{"sqref":"G33","active_cell":"G33","pane":"topRight"},{"sqref":"J60","active_cell":"J60","pane":"bottomLeft"},{"sqref":"O60","active_cell":"O60","pane":"bottomRight"}]}`)
 	xlsx.NewSheet("Panes 4")
 	xlsx.NewSheet("Panes 4")
 	xlsx.SetPanes("Panes 4", `{"freeze":true,"split":false,"x_split":0,"y_split":9,"top_left_cell":"A34","active_pane":"bottomLeft","panes":[{"sqref":"A11:XFD11","active_cell":"A11","pane":"bottomLeft"}]}`)
 	xlsx.SetPanes("Panes 4", `{"freeze":true,"split":false,"x_split":0,"y_split":9,"top_left_cell":"A34","active_pane":"bottomLeft","panes":[{"sqref":"A11:XFD11","active_cell":"A11","pane":"bottomLeft"}]}`)
+	xlsx.SetPanes("Panes 4", "")
 	err := xlsx.SaveAs("./test/Book_set_panes.xlsx")
 	err := xlsx.SaveAs("./test/Book_set_panes.xlsx")
 	if err != nil {
 	if err != nil {
 		t.Error(err)
 		t.Error(err)
@@ -1010,6 +1028,8 @@ func TestConditionalFormat(t *testing.T) {
 	xlsx.SetConditionalFormat("Sheet1", "K1:K10", `[{"type":"data_bar", "criteria":"=", "min_type":"min","max_type":"max","bar_color":"#638EC6"}]`)
 	xlsx.SetConditionalFormat("Sheet1", "K1:K10", `[{"type":"data_bar", "criteria":"=", "min_type":"min","max_type":"max","bar_color":"#638EC6"}]`)
 	// Use a formula to determine which cells to format.
 	// Use a formula to determine which cells to format.
 	xlsx.SetConditionalFormat("Sheet1", "L1:L10", fmt.Sprintf(`[{"type":"formula", "criteria":"L2<3", "format":%d}]`, format1))
 	xlsx.SetConditionalFormat("Sheet1", "L1:L10", fmt.Sprintf(`[{"type":"formula", "criteria":"L2<3", "format":%d}]`, format1))
+	// Test set invalid format set in conditional format
+	xlsx.SetConditionalFormat("Sheet1", "L1:L10", "")
 	err = xlsx.SaveAs("./test/Book_conditional_format.xlsx")
 	err = xlsx.SaveAs("./test/Book_conditional_format.xlsx")
 	if err != nil {
 	if err != nil {
 		t.Log(err)
 		t.Log(err)

+ 1 - 1
lib.go

@@ -50,7 +50,7 @@ func readFile(file *zip.File) []byte {
 		log.Fatal(err)
 		log.Fatal(err)
 	}
 	}
 	buff := bytes.NewBuffer(nil)
 	buff := bytes.NewBuffer(nil)
-	io.Copy(buff, rc)
+	_, _ = io.Copy(buff, rc)
 	rc.Close()
 	rc.Close()
 	return buff.Bytes()
 	return buff.Bytes()
 }
 }

+ 16 - 13
picture.go

@@ -16,7 +16,7 @@ import (
 
 
 // parseFormatPictureSet provides function to parse the format settings of the
 // parseFormatPictureSet provides function to parse the format settings of the
 // picture with default value.
 // picture with default value.
-func parseFormatPictureSet(formatSet string) *formatPicture {
+func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
 	format := formatPicture{
 	format := formatPicture{
 		FPrintsWithSheet: true,
 		FPrintsWithSheet: true,
 		FLocksWithSheet:  false,
 		FLocksWithSheet:  false,
@@ -26,8 +26,8 @@ func parseFormatPictureSet(formatSet string) *formatPicture {
 		XScale:           1.0,
 		XScale:           1.0,
 		YScale:           1.0,
 		YScale:           1.0,
 	}
 	}
-	json.Unmarshal([]byte(formatSet), &format)
-	return &format
+	err := json.Unmarshal([]byte(formatSet), &format)
+	return &format, err
 }
 }
 
 
 // AddPicture provides the method to add picture in a sheet by given picture
 // AddPicture provides the method to add picture in a sheet by given picture
@@ -89,9 +89,12 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
 		return errors.New("Unsupported image extension")
 		return errors.New("Unsupported image extension")
 	}
 	}
 	readFile, _ := os.Open(picture)
 	readFile, _ := os.Open(picture)
-	image, _, err := image.DecodeConfig(readFile)
+	image, _, _ := image.DecodeConfig(readFile)
 	_, file := filepath.Split(picture)
 	_, file := filepath.Split(picture)
-	formatSet := parseFormatPictureSet(format)
+	formatSet, err := parseFormatPictureSet(format)
+	if err != nil {
+		return err
+	}
 	// Read sheet data.
 	// Read sheet data.
 	xlsx := f.workSheetReader(sheet)
 	xlsx := f.workSheetReader(sheet)
 	// Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
 	// Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
@@ -130,7 +133,7 @@ func (f *File) addSheetRelationships(sheet, relType, target, targetMode string)
 	_, ok = f.XLSX[rels]
 	_, ok = f.XLSX[rels]
 	if ok {
 	if ok {
 		ID.Reset()
 		ID.Reset()
-		xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
+		_ = xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
 		rID = len(sheetRels.Relationships) + 1
 		rID = len(sheetRels.Relationships) + 1
 		ID.WriteString("rId")
 		ID.WriteString("rId")
 		ID.WriteString(strconv.Itoa(rID))
 		ID.WriteString(strconv.Itoa(rID))
@@ -156,7 +159,7 @@ func (f *File) deleteSheetRelationships(sheet, rID string) {
 	}
 	}
 	var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
 	var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
 	var sheetRels xlsxWorkbookRels
 	var sheetRels xlsxWorkbookRels
-	xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
+	_ = xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
 	for k, v := range sheetRels.Relationships {
 	for k, v := range sheetRels.Relationships {
 		if v.ID == rID {
 		if v.ID == rID {
 			sheetRels.Relationships = append(sheetRels.Relationships[:k], sheetRels.Relationships[k+1:]...)
 			sheetRels.Relationships = append(sheetRels.Relationships[:k], sheetRels.Relationships[k+1:]...)
@@ -273,7 +276,7 @@ func (f *File) addDrawingRelationships(index int, relType, target, targetMode st
 	_, ok := f.XLSX[rels]
 	_, ok := f.XLSX[rels]
 	if ok {
 	if ok {
 		ID.Reset()
 		ID.Reset()
-		xml.Unmarshal([]byte(f.readXML(rels)), &drawingRels)
+		_ = xml.Unmarshal([]byte(f.readXML(rels)), &drawingRels)
 		rID = len(drawingRels.Relationships) + 1
 		rID = len(drawingRels.Relationships) + 1
 		ID.WriteString("rId")
 		ID.WriteString("rId")
 		ID.WriteString(strconv.Itoa(rID))
 		ID.WriteString(strconv.Itoa(rID))
@@ -394,7 +397,7 @@ func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
 	}
 	}
 	var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
 	var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
 	var sheetRels xlsxWorkbookRels
 	var sheetRels xlsxWorkbookRels
-	xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
+	_ = xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
 	for _, v := range sheetRels.Relationships {
 	for _, v := range sheetRels.Relationships {
 		if v.ID == rID {
 		if v.ID == rID {
 			return v.Target
 			return v.Target
@@ -431,10 +434,10 @@ func (f *File) GetPicture(sheet, cell string) (string, []byte) {
 
 
 	_, ok := f.XLSX[drawingXML]
 	_, ok := f.XLSX[drawingXML]
 	if !ok {
 	if !ok {
-		return "", []byte{}
+		return "", nil
 	}
 	}
 	decodeWsDr := decodeWsDr{}
 	decodeWsDr := decodeWsDr{}
-	xml.Unmarshal([]byte(f.readXML(drawingXML)), &decodeWsDr)
+	_ = xml.Unmarshal([]byte(f.readXML(drawingXML)), &decodeWsDr)
 
 
 	cell = strings.ToUpper(cell)
 	cell = strings.ToUpper(cell)
 	fromCol := string(strings.Map(letterOnlyMapF, cell))
 	fromCol := string(strings.Map(letterOnlyMapF, cell))
@@ -446,7 +449,7 @@ func (f *File) GetPicture(sheet, cell string) (string, []byte) {
 
 
 	for _, anchor := range decodeWsDr.TwoCellAnchor {
 	for _, anchor := range decodeWsDr.TwoCellAnchor {
 		decodeTwoCellAnchor := decodeTwoCellAnchor{}
 		decodeTwoCellAnchor := decodeTwoCellAnchor{}
-		xml.Unmarshal([]byte("<decodeTwoCellAnchor>"+anchor.Content+"</decodeTwoCellAnchor>"), &decodeTwoCellAnchor)
+		_ = xml.Unmarshal([]byte("<decodeTwoCellAnchor>"+anchor.Content+"</decodeTwoCellAnchor>"), &decodeTwoCellAnchor)
 		if decodeTwoCellAnchor.From != nil && decodeTwoCellAnchor.Pic != nil {
 		if decodeTwoCellAnchor.From != nil && decodeTwoCellAnchor.Pic != nil {
 			if decodeTwoCellAnchor.From.Col == col && decodeTwoCellAnchor.From.Row == row {
 			if decodeTwoCellAnchor.From.Col == col && decodeTwoCellAnchor.From.Row == row {
 				xlsxWorkbookRelation := f.getDrawingRelationships(drawingRelationships, decodeTwoCellAnchor.Pic.BlipFill.Blip.Embed)
 				xlsxWorkbookRelation := f.getDrawingRelationships(drawingRelationships, decodeTwoCellAnchor.Pic.BlipFill.Blip.Embed)
@@ -468,7 +471,7 @@ func (f *File) getDrawingRelationships(rels, rID string) *xlsxWorkbookRelation {
 		return nil
 		return nil
 	}
 	}
 	var drawingRels xlsxWorkbookRels
 	var drawingRels xlsxWorkbookRels
-	xml.Unmarshal([]byte(f.readXML(rels)), &drawingRels)
+	_ = xml.Unmarshal([]byte(f.readXML(rels)), &drawingRels)
 	for _, v := range drawingRels.Relationships {
 	for _, v := range drawingRels.Relationships {
 		if v.ID == rID {
 		if v.ID == rID {
 			return &v
 			return &v

+ 7 - 7
rows.go

@@ -31,7 +31,7 @@ func (f *File) GetRows(sheet string) [][]string {
 		output, _ := xml.Marshal(f.Sheet[name])
 		output, _ := xml.Marshal(f.Sheet[name])
 		f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpaceBytes(output))
 		f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpaceBytes(output))
 	}
 	}
-	decoder := xml.NewDecoder(bytes.NewReader(f.readXML(name)))
+	xml.NewDecoder(bytes.NewReader(f.readXML(name)))
 	d := f.sharedStringsReader()
 	d := f.sharedStringsReader()
 	var inElement string
 	var inElement string
 	var r xlsxRow
 	var r xlsxRow
@@ -44,7 +44,7 @@ func (f *File) GetRows(sheet string) [][]string {
 		}
 		}
 		rows = append(rows, row)
 		rows = append(rows, row)
 	}
 	}
-	decoder = xml.NewDecoder(bytes.NewReader(f.readXML(name)))
+	decoder := xml.NewDecoder(bytes.NewReader(f.readXML(name)))
 	for {
 	for {
 		token, _ := decoder.Token()
 		token, _ := decoder.Token()
 		if token == nil {
 		if token == nil {
@@ -55,7 +55,7 @@ func (f *File) GetRows(sheet string) [][]string {
 			inElement = startElement.Name.Local
 			inElement = startElement.Name.Local
 			if inElement == "row" {
 			if inElement == "row" {
 				r = xlsxRow{}
 				r = xlsxRow{}
-				decoder.DecodeElement(&r, &startElement)
+				_ = decoder.DecodeElement(&r, &startElement)
 				cr := r.R - 1
 				cr := r.R - 1
 				for _, colCell := range r.C {
 				for _, colCell := range r.C {
 					c := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R))
 					c := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R))
@@ -110,9 +110,9 @@ func (rows *Rows) Columns() []string {
 	}
 	}
 	startElement := rows.token.(xml.StartElement)
 	startElement := rows.token.(xml.StartElement)
 	r := xlsxRow{}
 	r := xlsxRow{}
-	rows.decoder.DecodeElement(&r, &startElement)
+	_ = rows.decoder.DecodeElement(&r, &startElement)
 	d := rows.f.sharedStringsReader()
 	d := rows.f.sharedStringsReader()
-	row := make([]string, len(r.C), len(r.C))
+	row := make([]string, len(r.C))
 	for _, colCell := range r.C {
 	for _, colCell := range r.C {
 		c := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R))
 		c := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R))
 		val, _ := colCell.getValueFrom(rows.f, d)
 		val, _ := colCell.getValueFrom(rows.f, d)
@@ -173,7 +173,7 @@ func (f *File) getTotalRowsCols(name string) (int, int) {
 			inElement = startElement.Name.Local
 			inElement = startElement.Name.Local
 			if inElement == "row" {
 			if inElement == "row" {
 				r = xlsxRow{}
 				r = xlsxRow{}
-				decoder.DecodeElement(&r, &startElement)
+				_ = decoder.DecodeElement(&r, &startElement)
 				tr = r.R
 				tr = r.R
 				for _, colCell := range r.C {
 				for _, colCell := range r.C {
 					col := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R))
 					col := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R))
@@ -240,7 +240,7 @@ func (f *File) sharedStringsReader() *xlsxSST {
 		if len(ss) == 0 {
 		if len(ss) == 0 {
 			ss = f.readXML("xl/SharedStrings.xml")
 			ss = f.readXML("xl/SharedStrings.xml")
 		}
 		}
-		xml.Unmarshal([]byte(ss), &sharedStrings)
+		_ = xml.Unmarshal([]byte(ss), &sharedStrings)
 		f.SharedStrings = &sharedStrings
 		f.SharedStrings = &sharedStrings
 	}
 	}
 	return f.SharedStrings
 	return f.SharedStrings

+ 9 - 5
shape.go

@@ -9,7 +9,7 @@ import (
 
 
 // parseFormatShapeSet provides function to parse the format settings of the
 // parseFormatShapeSet provides function to parse the format settings of the
 // shape with default value.
 // shape with default value.
-func parseFormatShapeSet(formatSet string) *formatShape {
+func parseFormatShapeSet(formatSet string) (*formatShape, error) {
 	format := formatShape{
 	format := formatShape{
 		Width:  160,
 		Width:  160,
 		Height: 160,
 		Height: 160,
@@ -23,8 +23,8 @@ func parseFormatShapeSet(formatSet string) *formatShape {
 			YScale:           1.0,
 			YScale:           1.0,
 		},
 		},
 	}
 	}
-	json.Unmarshal([]byte(formatSet), &format)
-	return &format
+	err := json.Unmarshal([]byte(formatSet), &format)
+	return &format, err
 }
 }
 
 
 // AddShape provides the method to add shape in a sheet by given worksheet
 // AddShape provides the method to add shape in a sheet by given worksheet
@@ -245,8 +245,11 @@ func parseFormatShapeSet(formatSet string) *formatShape {
 //    wavyHeavy
 //    wavyHeavy
 //    wavyDbl
 //    wavyDbl
 //
 //
-func (f *File) AddShape(sheet, cell, format string) {
-	formatSet := parseFormatShapeSet(format)
+func (f *File) AddShape(sheet, cell, format string) error {
+	formatSet, err := parseFormatShapeSet(format)
+	if err != nil {
+		return err
+	}
 	// Read sheet data.
 	// Read sheet data.
 	xlsx := f.workSheetReader(sheet)
 	xlsx := f.workSheetReader(sheet)
 	// Add first shape for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
 	// Add first shape for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
@@ -266,6 +269,7 @@ func (f *File) AddShape(sheet, cell, format string) {
 	}
 	}
 	f.addDrawingShape(sheet, drawingXML, cell, formatSet)
 	f.addDrawingShape(sheet, drawingXML, cell, formatSet)
 	f.addContentTypePart(drawingID, "drawings")
 	f.addContentTypePart(drawingID, "drawings")
+	return err
 }
 }
 
 
 // addDrawingShape provides function to add preset geometry by given sheet,
 // addDrawingShape provides function to add preset geometry by given sheet,

+ 16 - 13
sheet.go

@@ -39,7 +39,7 @@ func (f *File) NewSheet(name string) int {
 func (f *File) contentTypesReader() *xlsxTypes {
 func (f *File) contentTypesReader() *xlsxTypes {
 	if f.ContentTypes == nil {
 	if f.ContentTypes == nil {
 		var content xlsxTypes
 		var content xlsxTypes
-		xml.Unmarshal([]byte(f.readXML("[Content_Types].xml")), &content)
+		_ = xml.Unmarshal([]byte(f.readXML("[Content_Types].xml")), &content)
 		f.ContentTypes = &content
 		f.ContentTypes = &content
 	}
 	}
 	return f.ContentTypes
 	return f.ContentTypes
@@ -59,7 +59,7 @@ func (f *File) contentTypesWriter() {
 func (f *File) workbookReader() *xlsxWorkbook {
 func (f *File) workbookReader() *xlsxWorkbook {
 	if f.WorkBook == nil {
 	if f.WorkBook == nil {
 		var content xlsxWorkbook
 		var content xlsxWorkbook
-		xml.Unmarshal([]byte(f.readXML("xl/workbook.xml")), &content)
+		_ = xml.Unmarshal([]byte(f.readXML("xl/workbook.xml")), &content)
 		f.WorkBook = &content
 		f.WorkBook = &content
 	}
 	}
 	return f.WorkBook
 	return f.WorkBook
@@ -142,7 +142,7 @@ func (f *File) setWorkbook(name string, rid int) {
 func (f *File) workbookRelsReader() *xlsxWorkbookRels {
 func (f *File) workbookRelsReader() *xlsxWorkbookRels {
 	if f.WorkBookRels == nil {
 	if f.WorkBookRels == nil {
 		var content xlsxWorkbookRels
 		var content xlsxWorkbookRels
-		xml.Unmarshal([]byte(f.readXML("xl/_rels/workbook.xml.rels")), &content)
+		_ = xml.Unmarshal([]byte(f.readXML("xl/_rels/workbook.xml.rels")), &content)
 		f.WorkBookRels = &content
 		f.WorkBookRels = &content
 	}
 	}
 	return f.WorkBookRels
 	return f.WorkBookRels
@@ -247,7 +247,7 @@ func (f *File) GetActiveSheetIndex() int {
 		buffer.WriteString("xl/worksheets/sheet")
 		buffer.WriteString("xl/worksheets/sheet")
 		buffer.WriteString(strings.TrimPrefix(v.ID, "rId"))
 		buffer.WriteString(strings.TrimPrefix(v.ID, "rId"))
 		buffer.WriteString(".xml")
 		buffer.WriteString(".xml")
-		xml.Unmarshal([]byte(f.readXML(buffer.String())), &xlsx)
+		_ = xml.Unmarshal([]byte(f.readXML(buffer.String())), &xlsx)
 		for _, sheetView := range xlsx.SheetViews.SheetView {
 		for _, sheetView := range xlsx.SheetViews.SheetView {
 			if sheetView.TabSelected {
 			if sheetView.TabSelected {
 				ID, _ := strconv.Atoi(strings.TrimPrefix(v.ID, "rId"))
 				ID, _ := strconv.Atoi(strings.TrimPrefix(v.ID, "rId"))
@@ -433,16 +433,18 @@ func (f *File) CopySheet(from, to int) error {
 	if from < 1 || to < 1 || from == to || f.GetSheetName(from) == "" || f.GetSheetName(to) == "" {
 	if from < 1 || to < 1 || from == to || f.GetSheetName(from) == "" || f.GetSheetName(to) == "" {
 		return errors.New("Invalid worksheet index")
 		return errors.New("Invalid worksheet index")
 	}
 	}
-	f.copySheet(from, to)
-	return nil
+	return f.copySheet(from, to)
 }
 }
 
 
 // copySheet provides function to duplicate a worksheet by gave source and
 // copySheet provides function to duplicate a worksheet by gave source and
 // target worksheet name.
 // target worksheet name.
-func (f *File) copySheet(from, to int) {
+func (f *File) copySheet(from, to int) error {
 	sheet := f.workSheetReader("sheet" + strconv.Itoa(from))
 	sheet := f.workSheetReader("sheet" + strconv.Itoa(from))
 	worksheet := xlsxWorksheet{}
 	worksheet := xlsxWorksheet{}
-	deepCopy(&worksheet, &sheet)
+	err := deepCopy(&worksheet, &sheet)
+	if err != nil {
+		return err
+	}
 	path := "xl/worksheets/sheet" + strconv.Itoa(to) + ".xml"
 	path := "xl/worksheets/sheet" + strconv.Itoa(to) + ".xml"
 	if len(worksheet.SheetViews.SheetView) > 0 {
 	if len(worksheet.SheetViews.SheetView) > 0 {
 		worksheet.SheetViews.SheetView[0].TabSelected = false
 		worksheet.SheetViews.SheetView[0].TabSelected = false
@@ -457,6 +459,7 @@ func (f *File) copySheet(from, to int) {
 	if ok {
 	if ok {
 		f.XLSX[toRels] = f.XLSX[fromRels]
 		f.XLSX[toRels] = f.XLSX[fromRels]
 	}
 	}
+	return err
 }
 }
 
 
 // SetSheetVisible provides function to set worksheet visible by given worksheet
 // SetSheetVisible provides function to set worksheet visible by given worksheet
@@ -502,10 +505,10 @@ func (f *File) SetSheetVisible(name string, visible bool) {
 }
 }
 
 
 // parseFormatPanesSet provides function to parse the panes settings.
 // parseFormatPanesSet provides function to parse the panes settings.
-func parseFormatPanesSet(formatSet string) *formatPanes {
+func parseFormatPanesSet(formatSet string) (*formatPanes, error) {
 	format := formatPanes{}
 	format := formatPanes{}
-	json.Unmarshal([]byte(formatSet), &format)
-	return &format
+	err := json.Unmarshal([]byte(formatSet), &format)
+	return &format, err
 }
 }
 
 
 // SetPanes provides function to create and remove freeze panes and split panes
 // SetPanes provides function to create and remove freeze panes and split panes
@@ -594,7 +597,7 @@ func parseFormatPanesSet(formatSet string) *formatPanes {
 //    xlsx.SetPanes("Sheet1", `{"freeze":false,"split":false}`)
 //    xlsx.SetPanes("Sheet1", `{"freeze":false,"split":false}`)
 //
 //
 func (f *File) SetPanes(sheet, panes string) {
 func (f *File) SetPanes(sheet, panes string) {
-	fs := parseFormatPanesSet(panes)
+	fs, _ := parseFormatPanesSet(panes)
 	xlsx := f.workSheetReader(sheet)
 	xlsx := f.workSheetReader(sheet)
 	p := &xlsxPane{
 	p := &xlsxPane{
 		ActivePane:  fs.ActivePane,
 		ActivePane:  fs.ActivePane,
@@ -644,7 +647,7 @@ func (f *File) GetSheetVisible(name string) bool {
 // name.
 // name.
 func trimSheetName(name string) string {
 func trimSheetName(name string) string {
 	r := []rune{}
 	r := []rune{}
-	for _, v := range []rune(name) {
+	for _, v := range name {
 		switch v {
 		switch v {
 		case 58, 92, 47, 63, 42, 91, 93: // replace :\/?*[]
 		case 58, 92, 47, 63, 42, 91, 93: // replace :\/?*[]
 			continue
 			continue

+ 7 - 4
styles.go

@@ -988,7 +988,7 @@ func is12HourTime(format string) bool {
 func (f *File) stylesReader() *xlsxStyleSheet {
 func (f *File) stylesReader() *xlsxStyleSheet {
 	if f.Styles == nil {
 	if f.Styles == nil {
 		var styleSheet xlsxStyleSheet
 		var styleSheet xlsxStyleSheet
-		xml.Unmarshal([]byte(f.readXML("xl/styles.xml")), &styleSheet)
+		_ = xml.Unmarshal([]byte(f.readXML("xl/styles.xml")), &styleSheet)
 		f.Styles = &styleSheet
 		f.Styles = &styleSheet
 	}
 	}
 	return f.Styles
 	return f.Styles
@@ -2562,10 +2562,12 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) {
 //
 //
 // bar_color - Used for data_bar. Same as min_color, see above.
 // bar_color - Used for data_bar. Same as min_color, see above.
 //
 //
-func (f *File) SetConditionalFormat(sheet, area, formatSet string) {
+func (f *File) SetConditionalFormat(sheet, area, formatSet string) error {
 	var format []*formatConditional
 	var format []*formatConditional
-	json.Unmarshal([]byte(formatSet), &format)
-
+	err := json.Unmarshal([]byte(formatSet), &format)
+	if err != nil {
+		return err
+	}
 	drawContFmtFunc := map[string]func(p int, ct string, fmtCond *formatConditional) *xlsxCfRule{
 	drawContFmtFunc := map[string]func(p int, ct string, fmtCond *formatConditional) *xlsxCfRule{
 		"cellIs":          drawCondFmtCellIs,
 		"cellIs":          drawCondFmtCellIs,
 		"top10":           drawCondFmtTop10,
 		"top10":           drawCondFmtTop10,
@@ -2601,6 +2603,7 @@ func (f *File) SetConditionalFormat(sheet, area, formatSet string) {
 		SQRef:  area,
 		SQRef:  area,
 		CfRule: cfRule,
 		CfRule: cfRule,
 	})
 	})
+	return err
 }
 }
 
 
 // drawCondFmtCellIs provides function to create conditional formatting rule for
 // drawCondFmtCellIs provides function to create conditional formatting rule for

+ 15 - 11
table.go

@@ -11,13 +11,13 @@ import (
 
 
 // parseFormatTableSet provides function to parse the format settings of the
 // parseFormatTableSet provides function to parse the format settings of the
 // table with default value.
 // table with default value.
-func parseFormatTableSet(formatSet string) *formatTable {
+func parseFormatTableSet(formatSet string) (*formatTable, error) {
 	format := formatTable{
 	format := formatTable{
 		TableStyle:     "",
 		TableStyle:     "",
 		ShowRowStripes: true,
 		ShowRowStripes: true,
 	}
 	}
-	json.Unmarshal([]byte(formatSet), &format)
-	return &format
+	err := json.Unmarshal([]byte(formatSet), &format)
+	return &format, err
 }
 }
 
 
 // AddTable provides the method to add table in a worksheet by given worksheet
 // AddTable provides the method to add table in a worksheet by given worksheet
@@ -41,8 +41,11 @@ func parseFormatTableSet(formatSet string) *formatTable {
 //    TableStyleMedium1 - TableStyleMedium28
 //    TableStyleMedium1 - TableStyleMedium28
 //    TableStyleDark1 - TableStyleDark11
 //    TableStyleDark1 - TableStyleDark11
 //
 //
-func (f *File) AddTable(sheet, hcell, vcell, format string) {
-	formatSet := parseFormatTableSet(format)
+func (f *File) AddTable(sheet, hcell, vcell, format string) error {
+	formatSet, err := parseFormatTableSet(format)
+	if err != nil {
+		return err
+	}
 	hcell = strings.ToUpper(hcell)
 	hcell = strings.ToUpper(hcell)
 	vcell = strings.ToUpper(vcell)
 	vcell = strings.ToUpper(vcell)
 	// Coordinate conversion, convert C1:B3 to 2,0,1,2.
 	// Coordinate conversion, convert C1:B3 to 2,0,1,2.
@@ -69,6 +72,7 @@ func (f *File) AddTable(sheet, hcell, vcell, format string) {
 	f.addSheetTable(sheet, rID)
 	f.addSheetTable(sheet, rID)
 	f.addTable(sheet, tableXML, hxAxis, hyAxis, vxAxis, vyAxis, tableID, formatSet)
 	f.addTable(sheet, tableXML, hxAxis, hyAxis, vxAxis, vyAxis, tableID, formatSet)
 	f.addContentTypePart(tableID, "table")
 	f.addContentTypePart(tableID, "table")
+	return err
 }
 }
 
 
 // countTables provides function to get table files count storage in the folder
 // countTables provides function to get table files count storage in the folder
@@ -155,10 +159,10 @@ func (f *File) addTable(sheet, tableXML string, hxAxis, hyAxis, vxAxis, vyAxis,
 
 
 // parseAutoFilterSet provides function to parse the settings of the auto
 // parseAutoFilterSet provides function to parse the settings of the auto
 // filter.
 // filter.
-func parseAutoFilterSet(formatSet string) *formatAutoFilter {
+func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
 	format := formatAutoFilter{}
 	format := formatAutoFilter{}
-	json.Unmarshal([]byte(formatSet), &format)
-	return &format
+	err := json.Unmarshal([]byte(formatSet), &format)
+	return &format, err
 }
 }
 
 
 // AutoFilter provides the method to add auto filter in a worksheet by given
 // AutoFilter provides the method to add auto filter in a worksheet by given
@@ -232,7 +236,8 @@ func parseAutoFilterSet(formatSet string) *formatAutoFilter {
 //    Price < 2000
 //    Price < 2000
 //
 //
 func (f *File) AutoFilter(sheet, hcell, vcell, format string) error {
 func (f *File) AutoFilter(sheet, hcell, vcell, format string) error {
-	formatSet := parseAutoFilterSet(format)
+	formatSet, _ := parseAutoFilterSet(format)
+
 	hcell = strings.ToUpper(hcell)
 	hcell = strings.ToUpper(hcell)
 	vcell = strings.ToUpper(vcell)
 	vcell = strings.ToUpper(vcell)
 
 
@@ -256,8 +261,7 @@ func (f *File) AutoFilter(sheet, hcell, vcell, format string) error {
 	}
 	}
 	ref := ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1) + ":" + ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1)
 	ref := ToAlphaString(hxAxis) + strconv.Itoa(hyAxis+1) + ":" + ToAlphaString(vxAxis) + strconv.Itoa(vyAxis+1)
 	refRange := vxAxis - hxAxis
 	refRange := vxAxis - hxAxis
-	err := f.autoFilter(sheet, ref, refRange, hxAxis, formatSet)
-	return err
+	return f.autoFilter(sheet, ref, refRange, hxAxis, formatSet)
 }
 }
 
 
 // autoFilter provides function to extract the tokens from the filter
 // autoFilter provides function to extract the tokens from the filter