diff --git a/README.md b/README.md index b20f5726..06783a5a 100644 --- a/README.md +++ b/README.md @@ -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 ## diff --git a/_examples/spreadsheet/complex/complex.xlsx b/_examples/spreadsheet/complex/complex.xlsx index 1c917729..52a3b6d4 100644 Binary files a/_examples/spreadsheet/complex/complex.xlsx and b/_examples/spreadsheet/complex/complex.xlsx differ diff --git a/_examples/spreadsheet/complex/main.go b/_examples/spreadsheet/complex/main.go index 2e1c8a9c..aa690860 100644 --- a/_examples/spreadsheet/complex/main.go +++ b/_examples/spreadsheet/complex/main.go @@ -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) diff --git a/_examples/spreadsheet/complex/preview.png b/_examples/spreadsheet/complex/preview.png new file mode 100644 index 00000000..20ad2e0c Binary files /dev/null and b/_examples/spreadsheet/complex/preview.png differ diff --git a/spreadsheet/column.go b/spreadsheet/column.go index b0db499b..c440d84e 100644 --- a/spreadsheet/column.go +++ b/spreadsheet/column.go @@ -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())