Documentation
¶
Overview ¶
export/csv.go
export/excel.go
Index ¶
- Constants
- Variables
- type CSV
- func (c *CSV) Bytes() ([]byte, error)
- func (c *CSV) Delimiter(d rune) *CSV
- func (c *CSV) From(data any) *CSV
- func (c *CSV) Headers(headers ...string) *CSV
- func (c *CSV) Row(values ...string) *CSV
- func (c *CSV) Rows(rows [][]string) *CSV
- func (c *CSV) Save(filename string) error
- func (c *CSV) ServeHTTP(w http.ResponseWriter, filename string) error
- func (c *CSV) String() (string, error)
- func (c *CSV) TabDelimited() *CSV
- func (c *CSV) UseLF() *CSV
- func (c *CSV) Write(w io.Writer) error
- type CSVReader
- type CellStyle
- type Excel
- type ExcelSheet
- func (s *ExcelSheet) AddFormula(col, row int, formula string) *ExcelSheet
- func (s *ExcelSheet) AddTable() *ExcelSheet
- func (s *ExcelSheet) AutoWidth() *ExcelSheet
- func (s *ExcelSheet) Build() *Excel
- func (s *ExcelSheet) ColWidth(col int, width float64) *ExcelSheet
- func (s *ExcelSheet) FreezeHeader() *ExcelSheet
- func (s *ExcelSheet) From(data any) *ExcelSheet
- func (s *ExcelSheet) Headers(headers ...string) *ExcelSheet
- func (s *ExcelSheet) MergeCells(startCol, startRow, endCol, endRow int) *ExcelSheet
- func (s *ExcelSheet) Row(values ...any) *ExcelSheet
- func (s *ExcelSheet) Rows(rows [][]any) *ExcelSheet
- func (s *ExcelSheet) SetCellStyle(startCol, startRow, endCol, endRow int, style CellStyle) *ExcelSheet
- func (s *ExcelSheet) SetDateFormat(col int, format string) *ExcelSheet
- func (s *ExcelSheet) SetNumberFormat(col int, format string) *ExcelSheet
- func (s *ExcelSheet) Sheet(name string) *ExcelSheet
- type TimeValue
Constants ¶
const ( NumberFormatGeneral = "General" NumberFormatInteger = "0" NumberFormatDecimal2 = "0.00" NumberFormatPercent = "0%" NumberFormatPercent2 = "0.00%" NumberFormatCurrency = `"$"#,##0.00` NumberFormatDate = "yyyy-mm-dd" NumberFormatDateTime = "yyyy-mm-dd hh:mm:ss" NumberFormatTime = "hh:mm:ss" NumberFormatAccounting = `_("$"* #,##0.00_)` )
Common number formats
Variables ¶
var ( ErrNoData = errors.New("export: no data to export") ErrInvalidData = errors.New("export: data must be a slice") ErrEmptyHeaders = errors.New("export: headers cannot be empty") )
Common errors.
Functions ¶
This section is empty.
Types ¶
type CSV ¶
type CSV struct {
// contains filtered or unexported fields
}
CSV represents a CSV exporter.
func (*CSV) ServeHTTP ¶
func (c *CSV) ServeHTTP(w http.ResponseWriter, filename string) error
ServeHTTP writes the CSV as an HTTP response.
func (*CSV) TabDelimited ¶
TabDelimited sets tab as the delimiter.
type CSVReader ¶
type CSVReader struct {
// contains filtered or unexported fields
}
CSVReader represents a CSV reader with struct mapping.
func ReadCSVFile ¶
ReadCSVFile opens and reads a CSV file.
func (*CSVReader) ReadAllWithHeaders ¶
ReadAllWithHeaders reads all records, treating the first row as headers.
func (*CSVReader) TabDelimited ¶
TabDelimited sets tab as the delimiter.
type CellStyle ¶
type CellStyle struct {
Bold bool
Italic bool
FontSize float64
FontColor string
FillColor string
Alignment string // left, center, right
NumFormat string
Border bool
}
CellStyle represents cell styling options.
type Excel ¶
type Excel struct {
// contains filtered or unexported fields
}
Excel represents an Excel workbook exporter.
func (*Excel) ServeHTTP ¶
func (e *Excel) ServeHTTP(w http.ResponseWriter, filename string) error
ServeHTTP writes the Excel file as an HTTP response.
func (*Excel) Sheet ¶
func (e *Excel) Sheet(name string) *ExcelSheet
Sheet creates or gets a sheet by name.
type ExcelSheet ¶
type ExcelSheet struct {
// contains filtered or unexported fields
}
ExcelSheet represents a sheet in an Excel workbook.
func FromExcel ¶
func FromExcel(data any) *ExcelSheet
FromExcel is a convenience function to create an Excel file from data.
func (*ExcelSheet) AddFormula ¶
func (s *ExcelSheet) AddFormula(col, row int, formula string) *ExcelSheet
AddFormula adds a formula to a cell.
func (*ExcelSheet) AddTable ¶
func (s *ExcelSheet) AddTable() *ExcelSheet
AddTable formats the data as an Excel table.
func (*ExcelSheet) AutoWidth ¶
func (s *ExcelSheet) AutoWidth() *ExcelSheet
AutoWidth enables auto-width for all columns based on content.
func (*ExcelSheet) Build ¶
func (s *ExcelSheet) Build() *Excel
Build writes the sheet data to the Excel file.
func (*ExcelSheet) ColWidth ¶
func (s *ExcelSheet) ColWidth(col int, width float64) *ExcelSheet
ColWidth sets the width of a column (1-indexed).
func (*ExcelSheet) FreezeHeader ¶
func (s *ExcelSheet) FreezeHeader() *ExcelSheet
FreezeHeader freezes the header row.
func (*ExcelSheet) From ¶
func (s *ExcelSheet) From(data any) *ExcelSheet
From populates the sheet from a slice of structs or maps.
func (*ExcelSheet) Headers ¶
func (s *ExcelSheet) Headers(headers ...string) *ExcelSheet
Headers sets the column headers.
func (*ExcelSheet) MergeCells ¶
func (s *ExcelSheet) MergeCells(startCol, startRow, endCol, endRow int) *ExcelSheet
MergeCells merges a range of cells.
func (*ExcelSheet) Rows ¶
func (s *ExcelSheet) Rows(rows [][]any) *ExcelSheet
Rows adds multiple rows.
func (*ExcelSheet) SetCellStyle ¶
func (s *ExcelSheet) SetCellStyle(startCol, startRow, endCol, endRow int, style CellStyle) *ExcelSheet
SetCellStyle sets style for a range of cells.
func (*ExcelSheet) SetDateFormat ¶
func (s *ExcelSheet) SetDateFormat(col int, format string) *ExcelSheet
SetDateFormat sets date format for a column.
func (*ExcelSheet) SetNumberFormat ¶
func (s *ExcelSheet) SetNumberFormat(col int, format string) *ExcelSheet
SetNumberFormat sets number format for a column.
func (*ExcelSheet) Sheet ¶
func (s *ExcelSheet) Sheet(name string) *ExcelSheet
Sheet returns to the Excel builder to add more sheets.
type TimeValue ¶
TimeValue wraps a time.Time with a specific format for Excel.
func ExcelDateTime ¶
ExcelDateTime creates a TimeValue with date and time format.