spreadsheet: add complex example

This has some conditional formatting, charts and auto filters.
This commit is contained in:
Todd 2017-09-09 10:12:13 -05:00
parent ceb8570558
commit 3d6b12368b
5 changed files with 32 additions and 25 deletions

View File

@ -35,14 +35,15 @@ and .pptx).
## Spreadsheet Examples ##
- [Simple](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/simple) A simple sheet with a few cells
- [Named Cells](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/named-cells) Different ways of referencing rows and cells.
- [Cell Number/Date/Time Formats](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/number-date-time-formats) Creating cells with various number/date/time formats.
- [Named Cells](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/named-cells) Different ways of referencing rows and cells
- [Cell Number/Date/Time Formats](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/number-date-time-formats) Creating cells with various number/date/time formats
- [Line Chart](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/line-chart)/[Line Chart 3D](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/line-chart-3d) Line Charts
- [Bar Chart](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/bar-chart) Bar Charts
- [Mutiple Charts](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/multiple-charts) Multiple charts on a single sheet
- [Named Cell Ranges](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/named-ranges) Naming cell ranges
- [Merged Cells](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/merged) Merge and unmerge cells.
- [Conditional Formatting](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/conditional-formatting) Conditionally formatting cells, styling, gradients, icons, data bar.
- [Merged Cells](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/merged) Merge and unmerge cells
- [Conditional Formatting](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/conditional-formatting) Conditionally formatting cells, styling, gradients, icons, data bar
- [Complex](https://github.com/baliance/gooxml/tree/master/_examples/spreadsheet/complex) Multiple charts, auto filtering and conditional formatting
## Raw Types ##

View File

@ -8,6 +8,7 @@ import (
"baliance.com/gooxml/chart"
"baliance.com/gooxml/color"
"baliance.com/gooxml/measurement"
"baliance.com/gooxml/spreadsheet"
sml "baliance.com/gooxml/schema/schemas.openxmlformats.org/spreadsheetml"
@ -17,17 +18,31 @@ func main() {
ss := spreadsheet.New()
sheet := ss.AddSheet()
// Create all of our data
hdrStyle := ss.StyleSheet.AddCellStyle()
f := ss.StyleSheet.Fills().AddFill()
pf := f.SetPatternFill()
pf.SetFgColor(color.LightGray)
hdrStyle.SetFill(f)
fnt := ss.StyleSheet.AddFont()
fnt.SetBold(true)
hdrStyle.SetFont(fnt)
row := sheet.AddRow()
/* hdrStyle := ss.StyleSheet.AddCellStyle()
pf := ss.StyleSheet.Fills().AddPatternFill()
pf.SetFgColor(color.LightGray)
hdrStyle.SetFill(pf)
*/
row.AddCell().SetString("Item")
row.AddCell().SetString("Price")
row.AddCell().SetString("# Sold")
row.AddCell().SetString("Total")
row.Cell("A").SetString("Item")
row.Cell("A").SetStyle(hdrStyle)
row.Cell("B").SetString("Price")
row.Cell("B").SetStyle(hdrStyle)
row.Cell("C").SetString("# Sold")
row.Cell("C").SetStyle(hdrStyle)
row.Cell("D").SetString("Total")
row.Cell("D").SetStyle(hdrStyle)
// Set some column widths
sheet.Column(1).SetWidth(1.5 * measurement.Inch)
sheet.Column(4).SetWidth(2 * measurement.Inch)
for r := 0; r < 5; r++ {
row := sheet.AddRow()
row.AddCell().SetString(fmt.Sprintf("Product %d", r+1))
@ -66,8 +81,8 @@ func main() {
addBar3DChart(chrt1)
addLineChart(chrt2)
anc1.SetWidth(9)
anc1.MoveTo(5, 1)
anc2.MoveTo(1, 23)
anc1.MoveTo(6, 1)
anc2.MoveTo(0, 9)
// and finally add the chart to the sheet
sheet.SetDrawing(dwng)

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 KiB

View File

@ -29,15 +29,6 @@ func (c Column) SetWidth(w measurement.Distance) {
c.x.WidthAttr = gooxml.Float64(float64(w / measurement.Character))
}
// SetBestFit controls if the column width should be 'best fit'.
func (c Column) SetBestFit(b bool) {
if !b {
c.x.BestFitAttr = nil
} else {
c.x.BestFitAttr = gooxml.Bool(true)
}
}
// SetStyle sets the cell style for an entire column.
func (c Column) SetStyle(cs CellStyle) {
c.x.StyleAttr = gooxml.Uint32(cs.Index())