Documentation
¶
Index ¶
- Constants
- Variables
- type CellFormatUpdate
- type CellFormatter
- type CellStyle
- type Color
- type Filter
- type NumberFormat
- type Record
- func (r Record) Background(column string, color Color) Record
- func (r Record) Bold(column string) Record
- func (r Record) Bool(column string, value bool) Record
- func (r Record) Day(column string, value time.Time) Record
- func (r Record) Float(column string, value float64) Record
- func (r Record) Get(column string) string
- func (r Record) GetBool(column string) (bool, error)
- func (r Record) GetDay(column string) (time.Time, error)
- func (r Record) GetFloat(column string) (float64, error)
- func (r Record) GetInt(column string) (int, error)
- func (r Record) GetStyle(column string) CellStyle
- func (r Record) Int(column string, value int) Record
- func (r Record) Italic(column string) Record
- func (r Record) NumberFormat(column string, format NumberFormat) Record
- func (r Record) Set(column, value string) Record
- func (r Record) Style(column string, style CellStyle) Record
- func (r Record) TextColor(column string, color Color) Record
- func (r Record) Underline(column string) Record
- type SheetService
- type Table
- func (t *Table) Append(service SheetService, records ...Record) error
- func (t *Table) ClearRow(service SheetService, rowIndex int) error
- func (t *Table) Create(service SheetService) error
- func (t *Table) DeleteRow(service SheetService, rowIndex int) error
- func (t *Table) Query(service SheetService, filter Filter) ([]Record, error)
- func (t *Table) ReadAll(service SheetService) ([]Record, error)
- func (t *Table) ReadCell(service SheetService, rowIndex int, column string) (string, error)
- func (t *Table) Replace(service SheetService, records ...Record) error
- func (t *Table) UpdateCell(service SheetService, rowIndex int, column, value string) error
- func (t *Table) UpdateCellStyle(service SheetService, rowIndex int, column string, style CellStyle) error
- func (t *Table) UpdateRow(service SheetService, rowIndex int, record Record) error
Constants ¶
const ( HorizontalAlignLeft = "LEFT" HorizontalAlignCenter = "CENTER" HorizontalAlignRight = "RIGHT" VerticalAlignTop = "TOP" VerticalAlignMiddle = "MIDDLE" VerticalAlignBottom = "BOTTOM" WrapStrategyOverflow = "OVERFLOW_CELL" WrapStrategyClip = "CLIP" WrapStrategyWrap = "WRAP" )
Horizontal and vertical alignment values accepted by CellStyle. These map directly to the Google Sheets API enum values.
Variables ¶
var ErrColumnNotFound = errors.New("column not found")
ErrColumnNotFound is returned when a referenced column does not exist in the table.
var ErrTableNotFound = errors.New("table not found")
ErrTableNotFound is returned when a requested table (sheet) does not exist.
Functions ¶
This section is empty.
Types ¶
type CellFormatUpdate ¶
CellFormatUpdate describes a single cell format change at 0-based sheet coordinates. RowIndex 0 is the header row; RowIndex 1 is the first data row.
type CellFormatter ¶
type CellFormatter interface {
UpdateCellFormats(spreadsheetID, sheetName string, updates []CellFormatUpdate) error
}
CellFormatter is an optional capability a SheetService may implement to apply cell-level formatting (bold, colors, number formats, etc.). When a backend does not implement CellFormatter, style information on records is silently ignored.
type CellStyle ¶
type CellStyle struct {
Bold *bool
Italic *bool
Underline *bool
Strikethrough *bool
FontFamily *string
FontSize *int
TextColor *Color
BackgroundColor *Color
HorizontalAlignment *string
VerticalAlignment *string
WrapStrategy *string
NumberFormat *NumberFormat
}
CellStyle describes optional visual formatting for a single cell. All fields are pointers so the caller can express "unset" distinctly from a zero value; only the set fields are applied.
type Color ¶
type Color struct {
R, G, B, A float32
}
Color represents an RGBA color with components in the [0,1] range, matching the Google Sheets API color model.
type NumberFormat ¶
NumberFormat describes how a numeric/date value should be displayed. Type is one of the Google Sheets number format types (e.g. "NUMBER", "CURRENCY", "DATE", "TIME", "DATE_TIME", "PERCENT", "TEXT"). Pattern is an optional format pattern (e.g. "#,##0.00", "yyyy-mm-dd").
type Record ¶
type Record struct {
Values map[string]string
Styles map[string]CellStyle
RowIndex int // 1-based data row index, set when read from a Table
}
Record represents a row of data in a Table. Values are keyed by column name.
func (Record) Background ¶
Background sets the background color for the cell at the given column.
func (Record) Bool ¶ added in v0.4.0
Bool sets a boolean value for the given column and returns the Record for chaining.
func (Record) Day ¶ added in v0.4.0
Day sets a date value for the given column in yyyy-mm-dd format and returns the Record for chaining.
func (Record) Float ¶ added in v0.4.0
Float sets a float value for the given column and returns the Record for chaining.
func (Record) GetDay ¶
GetDay returns the date value for the given column parsed from yyyy-mm-dd format.
func (Record) GetStyle ¶
GetStyle returns the CellStyle set for the given column (zero value if none).
func (Record) Int ¶ added in v0.4.0
Int sets an integer value for the given column and returns the Record for chaining.
func (Record) NumberFormat ¶
func (r Record) NumberFormat(column string, format NumberFormat) Record
NumberFormat sets the number format for the cell at the given column.
func (Record) Style ¶ added in v0.4.0
Style sets the full CellStyle for the given column, replacing any previously set style for that column.
type SheetService ¶
type SheetService interface {
// WithContext returns a new SheetService that uses the provided context for all operations.
WithContext(context.Context) SheetService
// CreateSheet adds a new sheet (tab) to the spreadsheet.
CreateSheet(spreadsheetID, title string) error
// GetRows returns all rows from the given range.
GetRows(spreadsheetID, readRange string) ([][]any, error)
// AppendRows appends rows to the given range.
AppendRows(spreadsheetID, appendRange string, values [][]any) error
// UpdateRows updates rows at the given range.
UpdateRows(spreadsheetID, updateRange string, values [][]any) error
// DeleteRow deletes a single row from the sheet.
// sheetRowIndex is the 0-based row index within the sheet.
DeleteRow(spreadsheetID, sheetName string, sheetRowIndex int) error
// ClearRows clears rows in the given range (blanks content, keeps the row).
ClearRows(spreadsheetID, clearRange string) error
// GetSheetNames returns the names of all sheets in the spreadsheet.
GetSheetNames(spreadsheetID string) ([]string, error)
}
SheetService defines the operations needed to interact with a spreadsheet backend.
type Table ¶
Table represents a sheet within a Google Spreadsheet, treating it as a database table.
func GetTable ¶
func GetTable(service SheetService, spreadsheetID, sheetName string) (*Table, error)
GetTable retrieves an existing Table by reading its header row from the given sheet. Returns ErrTableNotFound if the sheet does not exist.
func (*Table) Append ¶
func (t *Table) Append(service SheetService, records ...Record) error
Append adds one or more records as new rows at the end of the sheet. Returns ErrColumnNotFound if any record contains a column that is not defined in the table.
func (*Table) ClearRow ¶
func (t *Table) ClearRow(service SheetService, rowIndex int) error
ClearRow blanks the data row at the given 1-based row index. The row remains in the sheet but its contents are removed.
func (*Table) Create ¶
func (t *Table) Create(service SheetService) error
Create creates the sheet in the spreadsheet and writes the header row.
func (*Table) DeleteRow ¶
func (t *Table) DeleteRow(service SheetService, rowIndex int) error
DeleteRow removes the data row at the given 1-based row index.
func (*Table) Query ¶
func (t *Table) Query(service SheetService, filter Filter) ([]Record, error)
Query returns all records that match the filter. Each returned Record has its RowIndex set.
func (*Table) ReadAll ¶
func (t *Table) ReadAll(service SheetService) ([]Record, error)
ReadAll returns all records from the sheet (excluding the header row).
func (*Table) ReadCell ¶
ReadCell reads a single cell identified by the 1-based data row index and column name.
func (*Table) Replace ¶
func (t *Table) Replace(service SheetService, records ...Record) error
Replace removes all existing data rows from the sheet and writes the given records as the new contents. The header row is preserved. Returns ErrColumnNotFound if any record contains a column that is not defined in the table.
func (*Table) UpdateCell ¶
func (t *Table) UpdateCell(service SheetService, rowIndex int, column, value string) error
UpdateCell updates a single cell in the sheet identified by the 1-based data row index and column name.
func (*Table) UpdateCellStyle ¶
func (t *Table) UpdateCellStyle(service SheetService, rowIndex int, column string, style CellStyle) error
UpdateCellStyle applies the given style to a single cell identified by the 1-based data row index and column name. The backend must implement CellFormatter; otherwise the call is a no-op.
func (*Table) UpdateRow ¶
func (t *Table) UpdateRow(service SheetService, rowIndex int, record Record) error
UpdateRow replaces the data row at the given 1-based row index (row 1 is the first data row, not the header). Returns ErrColumnNotFound if the record contains a column that is not defined in the table.