Make DeleteChart delete multiple charts located on the same cell

formula
xuri 5 years ago
parent 0bb245523a
commit e2bd08c911
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7

@ -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. // 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 // combo: Specifies the create a chart that combines two or more chart types
// chart. For example, create a clustered column - line chart with data // in a single chart. For example, create a clustered column - line chart with
// Sheet1!$E$1:$L$15: // data Sheet1!$E$1:$L$15:
// //
// package main // 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) drawingXML := strings.Replace(f.getSheetRelationshipsTargetByID(sheet, ws.Drawing.RID), "..", "xl", -1)
wsDr, _ = f.drawingParser(drawingXML) wsDr, _ = f.drawingParser(drawingXML)
for idx, anchor := range wsDr.TwoCellAnchor { for idx := 0; idx < len(wsDr.TwoCellAnchor); idx++ {
if err = nil; anchor.From != nil && anchor.Pic == nil { if err = nil; wsDr.TwoCellAnchor[idx].From != nil && wsDr.TwoCellAnchor[idx].Pic == nil {
if anchor.From.Col == col && anchor.From.Row == row { if wsDr.TwoCellAnchor[idx].From.Col == col && wsDr.TwoCellAnchor[idx].From.Row == row {
wsDr.TwoCellAnchor = append(wsDr.TwoCellAnchor[:idx], wsDr.TwoCellAnchor[idx+1:]...) 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 // deleteChart provides a function to delete chart graphic frame by given by
// given coordinates. // given coordinates.
func (f *File) deleteChart(col, row int, drawingXML string, wsDr *xlsxWsDr) (err error) { func (f *File) deleteChart(col, row int, drawingXML string, wsDr *xlsxWsDr) (err error) {
var ( var deTwoCellAnchor *decodeTwoCellAnchor
deWsDr *decodeWsDr for idx := 0; idx < len(wsDr.TwoCellAnchor); idx++ {
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 {
deTwoCellAnchor = new(decodeTwoCellAnchor) 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 { Decode(deTwoCellAnchor); err != nil && err != io.EOF {
err = fmt.Errorf("xml decode error: %s", err) err = fmt.Errorf("xml decode error: %s", err)
return return
} }
if err = nil; deTwoCellAnchor.From != nil && deTwoCellAnchor.Pic == nil { 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:]...) wsDr.TwoCellAnchor = append(wsDr.TwoCellAnchor[:idx], wsDr.TwoCellAnchor[idx+1:]...)
idx--
} }
} }
} }

@ -563,7 +563,7 @@ func (f *File) drawPie3DChart(formatSet *formatChart) *cPlotArea {
// pie chart by given format sets. // pie chart by given format sets.
func (f *File) drawPieOfPieChart(formatSet *formatChart) *cPlotArea { func (f *File) drawPieOfPieChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{ return &cPlotArea{
PieChart: &cCharts{ OfPieChart: &cCharts{
OfPieType: &attrValString{ OfPieType: &attrValString{
Val: stringPtr("pie"), Val: stringPtr("pie"),
}, },
@ -580,7 +580,7 @@ func (f *File) drawPieOfPieChart(formatSet *formatChart) *cPlotArea {
// pie chart by given format sets. // pie chart by given format sets.
func (f *File) drawBarOfPieChart(formatSet *formatChart) *cPlotArea { func (f *File) drawBarOfPieChart(formatSet *formatChart) *cPlotArea {
return &cPlotArea{ return &cPlotArea{
PieChart: &cCharts{ OfPieChart: &cCharts{
OfPieType: &attrValString{ OfPieType: &attrValString{
Val: stringPtr("bar"), Val: stringPtr("bar"),
}, },

@ -331,10 +331,10 @@ type cCharts struct {
RadarStyle *attrValString `xml:"radarStyle"` RadarStyle *attrValString `xml:"radarStyle"`
ScatterStyle *attrValString `xml:"scatterStyle"` ScatterStyle *attrValString `xml:"scatterStyle"`
OfPieType *attrValString `xml:"ofPieType"` OfPieType *attrValString `xml:"ofPieType"`
SerLines *attrValString `xml:"serLines"`
VaryColors *attrValBool `xml:"varyColors"` VaryColors *attrValBool `xml:"varyColors"`
Wireframe *attrValBool `xml:"wireframe"` Wireframe *attrValBool `xml:"wireframe"`
Ser *[]cSer `xml:"ser"` Ser *[]cSer `xml:"ser"`
SerLines *attrValString `xml:"serLines"`
DLbls *cDLbls `xml:"dLbls"` DLbls *cDLbls `xml:"dLbls"`
Shape *attrValString `xml:"shape"` Shape *attrValString `xml:"shape"`
HoleSize *attrValInt `xml:"holeSize"` HoleSize *attrValInt `xml:"holeSize"`

Loading…
Cancel
Save