Browse Source

Replace bytes.NewReader(stringToBytes(s)) with strings.NewReader(s) (#610)

Olivier Mengué 5 năm trước cách đây
mục cha
commit
6e90fa6b1d
3 tập tin đã thay đổi với 4 bổ sung5 xóa
  1. 1 1
      drawing.go
  2. 1 1
      picture.go
  3. 2 3
      sparkline.go

+ 1 - 1
drawing.go

@@ -1288,7 +1288,7 @@ func (f *File) deleteDrawing(col, row int, drawingXML, drawingType string) (err
 	}
 	for idx := 0; idx < len(wsDr.TwoCellAnchor); idx++ {
 		deTwoCellAnchor = new(decodeTwoCellAnchor)
-		if err = f.xmlNewDecoder(bytes.NewReader(stringToBytes("<decodeTwoCellAnchor>" + wsDr.TwoCellAnchor[idx].GraphicFrame + "</decodeTwoCellAnchor>"))).
+		if err = f.xmlNewDecoder(strings.NewReader("<decodeTwoCellAnchor>" + wsDr.TwoCellAnchor[idx].GraphicFrame + "</decodeTwoCellAnchor>")).
 			Decode(deTwoCellAnchor); err != nil && err != io.EOF {
 			err = fmt.Errorf("xml decode error: %s", err)
 			return

+ 1 - 1
picture.go

@@ -512,7 +512,7 @@ func (f *File) getPicture(row, col int, drawingXML, drawingRelationships string)
 	err = nil
 	for _, anchor := range deWsDr.TwoCellAnchor {
 		deTwoCellAnchor = new(decodeTwoCellAnchor)
-		if err = f.xmlNewDecoder(bytes.NewReader(stringToBytes("<decodeTwoCellAnchor>" + anchor.Content + "</decodeTwoCellAnchor>"))).
+		if err = f.xmlNewDecoder(strings.NewReader("<decodeTwoCellAnchor>" + anchor.Content + "</decodeTwoCellAnchor>")).
 			Decode(deTwoCellAnchor); err != nil && err != io.EOF {
 			err = fmt.Errorf("xml decode error: %s", err)
 			return

+ 2 - 3
sparkline.go

@@ -10,7 +10,6 @@
 package excelize
 
 import (
-	"bytes"
 	"encoding/xml"
 	"errors"
 	"io"
@@ -509,14 +508,14 @@ func (f *File) appendSparkline(ws *xlsxWorksheet, group *xlsxX14SparklineGroup,
 		sparklineGroupsBytes, sparklineGroupBytes, extLstBytes []byte
 	)
 	decodeExtLst = new(decodeWorksheetExt)
-	if err = f.xmlNewDecoder(bytes.NewReader([]byte("<extLst>" + ws.ExtLst.Ext + "</extLst>"))).
+	if err = f.xmlNewDecoder(strings.NewReader("<extLst>" + ws.ExtLst.Ext + "</extLst>")).
 		Decode(decodeExtLst); err != nil && err != io.EOF {
 		return
 	}
 	for idx, ext = range decodeExtLst.Ext {
 		if ext.URI == ExtURISparklineGroups {
 			decodeSparklineGroups = new(decodeX14SparklineGroups)
-			if err = f.xmlNewDecoder(bytes.NewReader(stringToBytes(ext.Content))).
+			if err = f.xmlNewDecoder(strings.NewReader(ext.Content)).
 				Decode(decodeSparklineGroups); err != nil && err != io.EOF {
 				return
 			}