From cbc3fd21b79fbb819c1c341fc825701c04a0b473 Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 22 Jan 2020 01:08:18 +0800 Subject: Resolve #455, init delete picture from spreadsheet support --- chart.go | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) (limited to 'chart.go') diff --git a/chart.go b/chart.go index 2629f0b..227cdee 100644 --- a/chart.go +++ b/chart.go @@ -10,11 +10,8 @@ package excelize import ( - "bytes" "encoding/json" "errors" - "fmt" - "io" "strconv" "strings" ) @@ -766,7 +763,6 @@ func (f *File) AddChart(sheet, cell, format string, combo ...string) error { // DeleteChart provides a function to delete chart in XLSX by given worksheet // and cell name. func (f *File) DeleteChart(sheet, cell string) (err error) { - var wsDr *xlsxWsDr col, row, err := CellNameToCoordinates(cell) if err != nil { return @@ -781,38 +777,7 @@ func (f *File) DeleteChart(sheet, cell string) (err error) { return } drawingXML := strings.Replace(f.getSheetRelationshipsTargetByID(sheet, ws.Drawing.RID), "..", "xl", -1) - wsDr, _ = f.drawingParser(drawingXML) - for idx := 0; idx < len(wsDr.TwoCellAnchor); idx++ { - if err = nil; wsDr.TwoCellAnchor[idx].From != nil && wsDr.TwoCellAnchor[idx].Pic == nil { - if wsDr.TwoCellAnchor[idx].From.Col == col && wsDr.TwoCellAnchor[idx].From.Row == row { - wsDr.TwoCellAnchor = append(wsDr.TwoCellAnchor[:idx], wsDr.TwoCellAnchor[idx+1:]...) - idx-- - } - } - } - return f.deleteChart(col, row, drawingXML, wsDr) -} - -// deleteChart provides a function to delete chart graphic frame by given by -// given coordinates. -func (f *File) deleteChart(col, row int, drawingXML string, wsDr *xlsxWsDr) (err error) { - var deTwoCellAnchor *decodeTwoCellAnchor - for idx := 0; idx < len(wsDr.TwoCellAnchor); idx++ { - deTwoCellAnchor = new(decodeTwoCellAnchor) - if err = f.xmlNewDecoder(bytes.NewReader([]byte("" + wsDr.TwoCellAnchor[idx].GraphicFrame + ""))). - Decode(deTwoCellAnchor); err != nil && err != io.EOF { - err = fmt.Errorf("xml decode error: %s", err) - return - } - if err = nil; deTwoCellAnchor.From != nil && deTwoCellAnchor.Pic == nil { - if deTwoCellAnchor.From.Col == col && deTwoCellAnchor.From.Row == row { - wsDr.TwoCellAnchor = append(wsDr.TwoCellAnchor[:idx], wsDr.TwoCellAnchor[idx+1:]...) - idx-- - } - } - } - f.Drawings[drawingXML] = wsDr - return err + return f.deleteDrawing(col, row, drawingXML, "Chart") } // countCharts provides a function to get chart files count storage in the -- cgit v1.2.1