Skip to content

Commit

Permalink
spreadsheet: add complex example
Browse files Browse the repository at this point in the history
This has some conditional formatting, charts and auto filters.
  • Loading branch information
tbaliance committed Sep 9, 2017
1 parent ceb8570 commit 3d6b123
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##

Expand Down
Binary file modified _examples/spreadsheet/complex/complex.xlsx
Binary file not shown.
39 changes: 27 additions & 12 deletions _examples/spreadsheet/complex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
Binary file added _examples/spreadsheet/complex/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions spreadsheet/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 3d6b123

Please sign in to comment.