Skip to content

Package table provides functions to create and render xlsx tables. It is built atop of the tealeg/xlsx (https://github.com/tealeg/xlsx) package.

License

Notifications You must be signed in to change notification settings

vanillaiice/table

Repository files navigation

table Go Reference Go Report Card

Package table provides functions to create and render xlsx tables. It is built atop of the tealeg/xlsx package.

Example

package main

import (
	"github.com/vanillaiice/table"
)

func main() {
	tbl := table.NewTable()

	sheet, err := tbl.AddSheet("cars")
	if err != nil {
		panic(err)
	}

	title := table.RowTitle("Some Cars", 4, "medium")
	sheet.AddRows(title, table.NewRow())

	const (
		redHex    = "ffff0000"
		blueHex   = "ff0000ff"
		orangeHex = "ffff8c00"
	)

	rows := []*table.Row{
		table.NewRow().SetHeight(30).AddCells(
			table.NewCells(
				&table.NewCellOpts{Style: table.NewCellStyle().SetBold(true).SetItalic(true).SetAlignementH("center")},
				"Make", "Model", "Color", "Year",
			)...,
		),
		table.NewRow().AddCells(
			table.NewCells(
				&table.NewCellOpts{Style: table.NewCellStyle().SetWrapText(true).SetFontColor(redHex)},
				"Ford", "Mustang", "Red", 2014,
			)...,
		),
		table.NewRow().AddCells(
			table.NewCells(
				&table.NewCellOpts{Style: table.NewCellStyle().SetWrapText(true).SetFontColor(blueHex)},
				"Subaru", "WRX STI", "Blue", 1998,
			)...,
		),
		table.NewRow().AddCells(
			table.NewCells(
				&table.NewCellOpts{Style: table.NewCellStyle().SetWrapText(true).SetFontColor(orangeHex)},
				"Honda", "Civic EK9", "Orange", 1999,
			)...,
		),
	}

	table.AddOuterAndInnerBorderRow("thin", rows...)

	sheet.AddRows(rows...)

	if err := tbl.Render(); err != nil {
		panic(err)
	}

	if err := tbl.Save("cars.xlsx"); err != nil {
		panic(err)
	}
}

License

GPLv3

Author

vanillaiice

Credits

tealeg/xlsx

About

Package table provides functions to create and render xlsx tables. It is built atop of the tealeg/xlsx (https://github.com/tealeg/xlsx) package.

Topics

Resources

License

Stars

Watchers

Forks

Languages