spreadsheet: allow setting drawing extents

This commit is contained in:
Todd 2017-09-03 18:54:15 -05:00
parent 704a4c6963
commit 96a7f9dc80
2 changed files with 71 additions and 12 deletions

34
spreadsheet/cellmarker.go Normal file
View File

@ -0,0 +1,34 @@
// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting sales@baliance.com.
package spreadsheet
import sd "baliance.com/gooxml/schema/schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
// CellMarker represents a cell position
type CellMarker struct {
x *sd.CT_Marker
}
// X returns the inner wrapped XML type.
func (c CellMarker) X() *sd.CT_Marker {
return c.x
}
func (c CellMarker) Col() int32 {
return c.x.Col
}
func (c CellMarker) SetCol(col int32) {
c.x.Col = col
}
func (c CellMarker) Row() int32 {
return c.x.Row
}
func (c CellMarker) SetRow(row int32) {
c.x.Row = row
}

View File

@ -44,21 +44,46 @@ func (d Drawing) AddChart() Chart {
}
// maybe use a one cell anchor?
tca := sd.NewCT_TwoCellAnchor()
tca.EditAsAttr = sd.ST_EditAsOneCell
tca.From.Col = 5
tca.From.Row = 0
tca.To.Col = 10
tca.To.Row = 20
d.x.TwoCellAnchor = sd.NewCT_TwoCellAnchor()
d.x.TwoCellAnchor.EditAsAttr = sd.ST_EditAsOneCell
d.x.EG_Anchor = []*sd.EG_Anchor{&sd.EG_Anchor{TwoCellAnchor: tca}}
// provide a default size so its visible, if from/to are both 0,0 then the
// chart won't show up.
d.x.TwoCellAnchor.From.Col = 5
d.x.TwoCellAnchor.From.Row = 0
d.x.TwoCellAnchor.To.Col = 10
d.x.TwoCellAnchor.To.Row = 20
tca.Choice = &sd.EG_ObjectChoicesChoice{}
tca.Choice.GraphicFrame = sd.NewCT_GraphicalObjectFrame()
tca.Choice.GraphicFrame.Graphic = dml.NewGraphic()
tca.Choice.GraphicFrame.Graphic.GraphicData.UriAttr = "http://schemas.openxmlformats.org/drawingml/2006/chart"
d.x.TwoCellAnchor.Choice = &sd.EG_ObjectChoicesChoice{}
d.x.TwoCellAnchor.Choice.GraphicFrame = sd.NewCT_GraphicalObjectFrame()
d.x.TwoCellAnchor.Choice.GraphicFrame.Graphic = dml.NewGraphic()
d.x.TwoCellAnchor.Choice.GraphicFrame.Graphic.GraphicData.UriAttr = "http://schemas.openxmlformats.org/drawingml/2006/chart"
c := c.NewChart()
c.IdAttr = chartID
tca.Choice.GraphicFrame.Graphic.GraphicData.Any = []gooxml.Any{c}
d.x.TwoCellAnchor.Choice.GraphicFrame.Graphic.GraphicData.Any = []gooxml.Any{c}
return Chart{chart}
}
// TopLeft allows manipulating the top left position of the drawing.
func (d Drawing) TopLeft() CellMarker {
if d.x.TwoCellAnchor != nil {
return CellMarker{d.x.TwoCellAnchor.From}
}
if d.x.OneCellAnchor != nil {
return CellMarker{d.x.OneCellAnchor.From}
}
// this will crash if used...
return CellMarker{}
}
// BottomRight allows manipulating the bottom right position of the drawing.
func (d Drawing) BottomRight() CellMarker {
if d.x.TwoCellAnchor != nil {
return CellMarker{d.x.TwoCellAnchor.To}
}
// this will crash if used...
return CellMarker{}
}