diff options
author | xuri <xuri.me@gmail.com> | 2020-01-21 23:29:56 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2020-01-21 23:29:56 +0800 |
commit | e2bd08c9111b0141c66adf232edb2fd729afa63f (patch) | |
tree | e47339e0ffcd80eb36ca473c0a73f7e1f709185e /chart.go | |
parent | 0bb245523aada34c7b3d30f0f6e9b16d9f78e7b8 (diff) |
Make DeleteChart delete multiple charts located on the same cell
Diffstat (limited to 'chart.go')
-rw-r--r-- | chart.go | 31 |
1 files changed, 12 insertions, 19 deletions
@@ -694,9 +694,9 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) { // // Set chart size by dimension property. The dimension property is optional. The default width is 480, and height is 290. // -// combo: Specifies the create a chart that combines two art types in a single -// chart. For example, create a clustered column - line chart with data -// Sheet1!$E$1:$L$15: +// combo: Specifies the create a chart that combines two or more chart types +// in a single chart. For example, create a clustered column - line chart with +// data Sheet1!$E$1:$L$15: // // package main // @@ -782,10 +782,11 @@ func (f *File) DeleteChart(sheet, cell string) (err error) { } drawingXML := strings.Replace(f.getSheetRelationshipsTargetByID(sheet, ws.Drawing.RID), "..", "xl", -1) wsDr, _ = f.drawingParser(drawingXML) - for idx, anchor := range wsDr.TwoCellAnchor { - if err = nil; anchor.From != nil && anchor.Pic == nil { - if anchor.From.Col == col && anchor.From.Row == row { + 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-- } } } @@ -795,26 +796,18 @@ func (f *File) DeleteChart(sheet, cell string) (err error) { // 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 ( - deWsDr *decodeWsDr - deTwoCellAnchor *decodeTwoCellAnchor - ) - deWsDr = new(decodeWsDr) - if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(drawingXML)))). - Decode(deWsDr); err != nil && err != io.EOF { - err = fmt.Errorf("xml decode error: %s", err) - return - } - for idx, anchor := range deWsDr.TwoCellAnchor { + var deTwoCellAnchor *decodeTwoCellAnchor + for idx := 0; idx < len(wsDr.TwoCellAnchor); idx++ { deTwoCellAnchor = new(decodeTwoCellAnchor) - if err = f.xmlNewDecoder(bytes.NewReader([]byte("<decodeTwoCellAnchor>" + anchor.Content + "</decodeTwoCellAnchor>"))). + if err = f.xmlNewDecoder(bytes.NewReader([]byte("<decodeTwoCellAnchor>" + wsDr.TwoCellAnchor[idx].GraphicFrame + "</decodeTwoCellAnchor>"))). 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 anchor.From.Col == col && anchor.From.Row == row { + if deTwoCellAnchor.From.Col == col && deTwoCellAnchor.From.Row == row { wsDr.TwoCellAnchor = append(wsDr.TwoCellAnchor[:idx], wsDr.TwoCellAnchor[idx+1:]...) + idx-- } } } |