Documentation ¶
Index ¶
- Constants
- Variables
- func ColIndexToLetters(colRef int) string
- func ColLettersToIndex(letters string) int
- func FileToSlice(path string) ([][][]string, error)
- func FileToSliceUnmerged(path string) ([][][]string, error)
- func GetCellIDStringFromCoords(x, y int) string
- func GetCellIDStringFromCoordsWithFixed(x, y int, xFixed, yFixed bool) string
- func GetCoordsFromCellIDString(cellIDString string) (x, y int, error error)
- func HSLToRGB(h, s, l float64) (r, g, b uint8)
- func MakeDefaultContentTypes() (types xlsxTypes)
- func NewXlsxCellDataValidation(allowBlank bool) *xlsxCellDataValidation
- func RGBToHSL(r, g, b uint8) (h, s, l float64)
- func RowIndexToString(rowRef int) string
- func SetDefaultFont(size int, name string)
- func TimeFromExcelTime(excelTime float64, date1904 bool) time.Time
- func TimeToExcelTime(t time.Time, date1904 bool) float64
- func TimeToUTCTime(t time.Time) time.Time
- type Alignment
- type AutoFilter
- type Border
- type Cell
- func (c *Cell) Bool() bool
- func (c *Cell) Float() (float64, error)
- func (c *Cell) FormattedValue() (string, error)
- func (c *Cell) Formula() string
- func (c *Cell) GeneralNumeric() (string, error)
- func (c *Cell) GeneralNumericWithoutScientific() (string, error)
- func (c *Cell) GetNumberFormat() string
- func (c *Cell) GetStyle() *Style
- func (c *Cell) GetTime(date1904 bool) (t time.Time, err error)
- func (c *Cell) Int() (int, error)
- func (c *Cell) Int64() (int64, error)
- func (c *Cell) IsTime() bool
- func (c *Cell) Merge(hcells, vcells int)
- func (c *Cell) SetBool(b bool)
- func (c *Cell) SetDataValidation(dd *xlsxCellDataValidation)
- func (c *Cell) SetDate(t time.Time)
- func (c *Cell) SetDateTime(t time.Time)
- func (c *Cell) SetDateTimeWithFormat(n float64, format string)
- func (c *Cell) SetDateWithOptions(t time.Time, options DateTimeOptions)
- func (c *Cell) SetFloat(n float64)
- func (c *Cell) SetFloatWithFormat(n float64, format string)
- func (c *Cell) SetFormat(format string)
- func (c *Cell) SetFormula(formula string)
- func (c *Cell) SetInt(n int)
- func (c *Cell) SetInt64(n int64)
- func (c *Cell) SetString(s string)
- func (c *Cell) SetStringFormula(formula string)
- func (c *Cell) SetStyle(style *Style)
- func (c *Cell) SetValue(n interface{})
- func (c *Cell) String() string
- func (c *Cell) Type() CellType
- type CellInterface
- type CellMetadata
- type CellType
- type Col
- func (c *Col) GetStreamStyle() StreamStyle
- func (c *Col) GetStyle() *Style
- func (c *Col) SetCellMetadata(cellMetadata CellMetadata)
- func (c *Col) SetDataValidation(dd *xlsxCellDataValidation, start, end int)
- func (c *Col) SetDataValidationWithStart(dd *xlsxCellDataValidation, start int)
- func (c *Col) SetStreamStyle(style StreamStyle)
- func (c *Col) SetStyle(style *Style)
- func (c *Col) SetType(cellType CellType)
- type DataValidationErrorStyle
- type DataValidationOperator
- type DataValidationType
- type DateTimeOptions
- type File
- func NewFile() *File
- func OpenBinary(bs []byte) (*File, error)
- func OpenBinaryWithRowLimit(bs []byte, rowLimit int) (*File, error)
- func OpenFile(fileName string) (file *File, err error)
- func OpenFileWithRowLimit(fileName string, rowLimit int) (file *File, err error)
- func OpenReaderAt(r io.ReaderAt, size int64) (*File, error)
- func OpenReaderAtWithRowLimit(r io.ReaderAt, size int64, rowLimit int) (*File, error)
- func ReadZip(f *zip.ReadCloser) (*File, error)
- func ReadZipReader(r *zip.Reader) (*File, error)
- func ReadZipReaderWithRowLimit(r *zip.Reader, rowLimit int) (*File, error)
- func ReadZipWithRowLimit(f *zip.ReadCloser, rowLimit int) (*File, error)
- func (f *File) AddSheet(sheetName string) (*Sheet, error)
- func (f *File) AppendSheet(sheet Sheet, sheetName string) (*Sheet, error)
- func (f *File) MarshallParts() (map[string]string, error)
- func (f *File) Save(path string) (err error)
- func (f *File) ToSlice() (output [][][]string, err error)
- func (f *File) ToSliceUnmerged() (output [][][]string, err error)
- func (f *File) Write(writer io.Writer) (err error)
- type Fill
- type Font
- type HSL
- type Pane
- type RefTable
- type Row
- type Sheet
- func (s *Sheet) AddRow() *Row
- func (s *Sheet) AddRowAtIndex(index int) (*Row, error)
- func (sh *Sheet) Cell(row, col int) *Cell
- func (s *Sheet) Col(idx int) *Col
- func (s *Sheet) RemoveRowAtIndex(index int) error
- func (s *Sheet) Row(idx int) *Row
- func (s *Sheet) SetColWidth(startcol, endcol int, width float64) error
- type SheetFormat
- type SheetView
- type StreamCell
- func NewDateStreamCell(t time.Time) StreamCell
- func NewIntegerStreamCell(cellData int) StreamCell
- func NewStreamCell(cellData string, cellStyle StreamStyle, cellType CellType) StreamCell
- func NewStringStreamCell(cellData string) StreamCell
- func NewStyledIntegerStreamCell(cellData int, cellStyle StreamStyle) StreamCell
- func NewStyledStringStreamCell(cellData string, cellStyle StreamStyle) StreamCell
- type StreamFile
- func (sf *StreamFile) Close() error
- func (sf *StreamFile) Error() error
- func (sf *StreamFile) Flush()
- func (sf *StreamFile) NextSheet() error
- func (sf *StreamFile) Write(cells []string) error
- func (sf *StreamFile) WriteAll(records [][]string) error
- func (sf *StreamFile) WriteAllS(records [][]StreamCell) error
- func (sf *StreamFile) WriteS(cells []StreamCell) error
- func (sf *StreamFile) WriteWithColumnDefaultMetadata(cells []string) error
- type StreamFileBuilder
- func (sb *StreamFileBuilder) AddSheet(name string, headers []string, cellTypes []*CellType) error
- func (sb *StreamFileBuilder) AddSheetS(name string, columnStyles []StreamStyle) error
- func (sb *StreamFileBuilder) AddSheetWithDefaultColumnMetadata(name string, headers []string, columnsDefaultCellMetadata []*CellMetadata) error
- func (sb *StreamFileBuilder) AddStreamStyle(streamStyle StreamStyle) error
- func (sb *StreamFileBuilder) AddStreamStyleList(streamStyles []StreamStyle) error
- func (sb *StreamFileBuilder) AddValidation(sheetIndex, colIndex, rowStartIndex int, validation *xlsxCellDataValidation)
- func (sb *StreamFileBuilder) Build() (*StreamFile, error)
- type StreamStyle
- func MakeDateStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle
- func MakeDecimalStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle
- func MakeIntegerStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle
- func MakeStringStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle
- func MakeStyle(numFormatId int, font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle
- type Style
- type WorkBookRels
- type XLSXReaderError
- type XLSXUnmarshaler
Constants ¶
const ( DataValidationTypeCustom DataValidationTypeDate DataValidationTypeDecimal DataValidationTypeTextLeng DataValidationTypeTime // DataValidationTypeWhole Integer DataValidationTypeWhole )
Data validation types
const ( DataValidationOperatorBetween DataValidationOperatorEqual DataValidationOperatorGreaterThan DataValidationOperatorGreaterThanOrEqual DataValidationOperatorLessThan DataValidationOperatorLessThanOrEqual DataValidationOperatorNotBetween DataValidationOperatorNotEqual )
Data validation operators
const ( MJD_0 float64 = 2400000.5 MJD_JD2000 float64 = 51544.5 )
const ( GeneralFormat = 0 IntegerFormat = 1 DecimalFormat = 2 DateFormat_dd_mm_yy = 14 DateTimeFormat_d_m_yy_h_mm = 22 )
const ( Helvetica = "Helvetica" Baskerville = "Baskerville Old Face" TimesNewRoman = "Times New Roman" Bodoni = "Bodoni MT" GillSans = "Gill Sans MT" Courier = "Courier" )
Several popular font names that can be used to create fonts
const ( RGB_Light_Green = "FFC6EFCE" RGB_Dark_Green = "FF006100" RGB_Light_Red = "FFFFC7CE" RGB_Dark_Red = "FF9C0006" RGB_White = "00000000" RGB_Black = "FFFFFFFF" )
const ColWidth = 9.5
Default column width in excel
const Excel2006MaxRowCount = 1048576
const Excel2006MaxRowIndex = Excel2006MaxRowCount - 1
const NoRowLimit int = -1
const (
Solid_Cell_Fill = "solid"
)
const TEMPLATE_DOCPROPS_APP = `` /* 308-byte string literal not displayed */
const TEMPLATE_DOCPROPS_CORE = `` /* 364-byte string literal not displayed */
const TEMPLATE_XL_THEME_THEME = `` /* 10940-byte string literal not displayed */
const TEMPLATE__RELS_DOT_RELS = `` /* 580-byte string literal not displayed */
Variables ¶
var ( DefaultDateFormat = builtInNumFmt[14] DefaultDateTimeFormat = builtInNumFmt[22] DefaultDateOptions = DateTimeOptions{ Location: timeLocationUTC, ExcelTimeFormat: DefaultDateFormat, } DefaultDateTimeOptions = DateTimeOptions{ Location: timeLocationUTC, ExcelTimeFormat: DefaultDateTimeFormat, } )
var ( NoCurrentSheetError = errors.New("no Current Sheet") WrongNumberOfRowsError = errors.New("invalid number of cells passed to Write. All calls to Write on the same sheet must have the same number of cells") AlreadyOnLastSheetError = errors.New("NextSheet() called, but already on last sheet") UnsupportedCellTypeError = errors.New("the given cell type is not supported") )
var BuiltStreamFileBuilderError = errors.New("StreamFileBuilder has already been built, functions may no longer be used")
var HSLModel = color.ModelFunc(hslModel)
HSLModel converts any color.Color to a HSL color.
Functions ¶
func ColIndexToLetters ¶
ColIndexToLetters is used to convert a zero based, numeric column indentifier into a character code.
func ColLettersToIndex ¶
ColLettersToIndex is used to convert a character based column reference to a zero based numeric column identifier.
func FileToSlice ¶
A convenient wrapper around File.ToSlice, FileToSlice will return the raw data contained in an Excel XLSX file as three dimensional slice. The first index represents the sheet number, the second the row number, and the third the cell number.
For example:
var mySlice [][][]string var value string mySlice = xlsx.FileToSlice("myXLSX.xlsx") value = mySlice[0][0][0]
Here, value would be set to the raw value of the cell A1 in the first sheet in the XLSX file.
func FileToSliceUnmerged ¶
FileToSliceUnmerged is a wrapper around File.ToSliceUnmerged. It returns the raw data contained in an Excel XLSX file as three dimensional slice. Merged cells will be unmerged. Covered cells become the values of theirs origins.
func GetCellIDStringFromCoords ¶
GetCellIDStringFromCoords returns the Excel format cell name that represents a pair of zero based cartesian coordinates.
func GetCellIDStringFromCoordsWithFixed ¶
GetCellIDStringFromCoordsWithFixed returns the Excel format cell name that represents a pair of zero based cartesian coordinates. It can specify either value as fixed.
func GetCoordsFromCellIDString ¶
GetCoordsFromCellIDString returns the zero based cartesian coordinates from a cell name in Excel format, e.g. the cellIDString "A1" returns 0, 0 and the "B3" return 1, 2.
func MakeDefaultContentTypes ¶
func MakeDefaultContentTypes() (types xlsxTypes)
func NewXlsxCellDataValidation ¶
func NewXlsxCellDataValidation(allowBlank bool) *xlsxCellDataValidation
NewXlsxCellDataValidation return data validation struct
func RowIndexToString ¶
RowIndexToString is used to convert a zero based, numeric row indentifier into its string representation.
func SetDefaultFont ¶
func TimeFromExcelTime ¶
Convert an excelTime representation (stored as a floating point number) to a time.Time.
func TimeToExcelTime ¶
TimeToExcelTime will convert a time.Time into Excel's float representation, in either 1900 or 1904 mode. If you don't know which to use, set date1904 to false. TODO should this should handle Julian dates?
Types ¶
type Alignment ¶
type Alignment struct { Horizontal string Indent int ShrinkToFit bool TextRotation int Vertical string WrapText bool }
func DefaultAlignment ¶
func DefaultAlignment() *Alignment
type AutoFilter ¶
type Border ¶
type Border struct { Left string LeftColor string Right string RightColor string Top string TopColor string Bottom string BottomColor string }
Border is a high level structure intended to provide user access to the contents of Border Style within an Sheet.
func DefaultBorder ¶
func DefaultBorder() *Border
type Cell ¶
type Cell struct { Row *Row Value string NumFmt string Hidden bool HMerge int VMerge int DataValidation *xlsxCellDataValidation // contains filtered or unexported fields }
Cell is a high level structure intended to provide user access to the contents of Cell within an xlsx.Row.
func (*Cell) Bool ¶
Bool returns a boolean from a cell's value. TODO: Determine if the current return value is appropriate for types other than CellTypeBool.
func (*Cell) FormattedValue ¶
FormattedValue returns a value, and possibly an error condition from a Cell. If it is possible to apply a format to the cell value, it will do so, if not then an error will be returned, along with the raw value of the Cell.
func (*Cell) GeneralNumeric ¶
GeneralNumeric returns the value of the cell as a string. It is formatted very closely to the the XLSX spec for how to display values when the storage type is Number and the format type is General. It is not 100% identical to the spec but is as close as you can get using the built in Go formatting tools.
func (*Cell) GeneralNumericWithoutScientific ¶
GeneralNumericWithoutScientific returns numbers that are always formatted as numbers, but it does not follow the rules for when XLSX should switch to scientific notation, since sometimes scientific notation is not desired, even if that is how the document is supposed to be formatted.
func (*Cell) GetNumberFormat ¶
GetNumberFormat returns the number format string for a cell.
func (*Cell) Int ¶
Int returns the value of cell as integer. Has max 53 bits of precision See: float64(int64(math.MaxInt))
func (*Cell) SetDataValidation ¶
func (c *Cell) SetDataValidation(dd *xlsxCellDataValidation)
SetDataValidation set data validation
func (*Cell) SetDateTime ¶
func (*Cell) SetDateTimeWithFormat ¶
func (*Cell) SetDateWithOptions ¶
func (c *Cell) SetDateWithOptions(t time.Time, options DateTimeOptions)
SetDateWithOptions allows for more granular control when exporting dates and times
func (*Cell) SetFloatWithFormat ¶
SetFloatWithFormat sets the value of a cell to a float and applies formatting to the cell.
func (*Cell) SetFormula ¶
SetFormula sets the format string for a cell.
func (*Cell) SetStringFormula ¶
func (*Cell) SetValue ¶
func (c *Cell) SetValue(n interface{})
SetInt sets a cell's value to an integer.
type CellInterface ¶
CellInterface defines the public API of the Cell.
type CellMetadata ¶
type CellMetadata struct {
// contains filtered or unexported fields
}
CellMetadata represents anything attributable to a cell except for the cell data itself. For example, it is used in StreamFileBuilder.AddSheetWithDefaultColumnMetadata to associate default attributes for cells in a particular column
var ( DefaultStringCellMetadata CellMetadata DefaultNumericCellMetadata CellMetadata DefaultDecimalCellMetadata CellMetadata DefaultIntegerCellMetadata CellMetadata DefaultDateCellMetadata CellMetadata )
func MakeCellMetadata ¶
func MakeCellMetadata(cellType CellType, streamStyle StreamStyle) CellMetadata
func (CellMetadata) Ptr ¶
func (cm CellMetadata) Ptr() *CellMetadata
type CellType ¶
type CellType int
CellType is an int type for storing metadata about the data type in the cell.
const ( CellTypeString CellType = iota // CellTypeStringFormula is a specific format for formulas that return string values. Formulas that return numbers // and booleans are stored as those types. CellTypeStringFormula CellTypeNumeric CellTypeBool // CellTypeInline is not respected on save, all inline string cells will be saved as SharedStrings // when saving to an XLSX file. This the same behavior as that found in Excel. CellTypeInline CellTypeError // d (Date): Cell contains a date in the ISO 8601 format. // That is the only mention of this format in the XLSX spec. // Date seems to be unused by the current version of Excel, it stores dates as Numeric cells with a date format string. // For now these cells will have their value output directly. It is unclear if the value is supposed to be parsed // into a number and then formatted using the formatting or not. CellTypeDate )
These are the cell types from the ST_CellType spec
type Col ¶
type Col struct { Min int Max int Hidden bool Width float64 Collapsed bool OutlineLevel uint8 DataValidation []*xlsxCellDataValidation // contains filtered or unexported fields }
func (*Col) GetStreamStyle ¶
func (c *Col) GetStreamStyle() StreamStyle
func (*Col) SetCellMetadata ¶
func (c *Col) SetCellMetadata(cellMetadata CellMetadata)
SetCellMetadata sets the CellMetadata related attributes of a Col
func (*Col) SetDataValidation ¶
SetDataValidation set data validation with zero based start and end. Set end to -1 for all rows.
func (*Col) SetDataValidationWithStart ¶
SetDataValidationWithStart set data validation with a zero basd start row. This will apply to the rest of the rest of the column.
func (*Col) SetStreamStyle ¶
func (c *Col) SetStreamStyle(style StreamStyle)
SetStreamStyle sets the style and number format id to the ones specified in the given StreamStyle
type DataValidationErrorStyle ¶
type DataValidationErrorStyle int
const ( StyleStop DataValidationErrorStyle StyleWarning StyleInformation )
Data validation error styles
type DataValidationType ¶
type DataValidationType int
type DateTimeOptions ¶
type DateTimeOptions struct { // Location allows calculating times in other timezones/locations Location *time.Location // ExcelTimeFormat is the string you want excel to use to format the datetime ExcelTimeFormat string }
DateTimeOptions are additional options for exporting times
type File ¶
type File struct { Date1904 bool Sheets []*Sheet Sheet map[string]*Sheet DefinedNames []*xlsxDefinedName // contains filtered or unexported fields }
File is a high level structure providing a slice of Sheet structs to the user.
func OpenBinary ¶
OpenBinary() take bytes of an XLSX file and returns a populated xlsx.File struct for it.
func OpenBinaryWithRowLimit ¶
OpenBinaryWithRowLimit() take bytes of an XLSX file and returns a populated xlsx.File struct for it.
func OpenFile ¶
OpenFile() take the name of an XLSX file and returns a populated xlsx.File struct for it.
func OpenFileWithRowLimit ¶
OpenFileWithRowLimit() will open the file, but will only read the specified number of rows. If you save this file, it will be truncated to the number of rows specified.
func OpenReaderAt ¶
OpenReaderAt() take io.ReaderAt of an XLSX file and returns a populated xlsx.File struct for it.
func OpenReaderAtWithRowLimit ¶
OpenReaderAtWithRowLimit() take io.ReaderAt of an XLSX file and returns a populated xlsx.File struct for it.
func ReadZip ¶
func ReadZip(f *zip.ReadCloser) (*File, error)
ReadZip() takes a pointer to a zip.ReadCloser and returns a xlsx.File struct populated with its contents. In most cases ReadZip is not used directly, but is called internally by OpenFile.
func ReadZipReader ¶
ReadZipReader() can be used to read an XLSX in memory without touching the filesystem.
func ReadZipReaderWithRowLimit ¶
ReadZipReaderWithRowLimit() can be used to read an XLSX in memory without touching the filesystem. rowLimit is the number of rows that should be read from the file. If rowLimit is -1, no limit is applied. You can specify this with the constant NoRowLimit.
func ReadZipWithRowLimit ¶
func ReadZipWithRowLimit(f *zip.ReadCloser, rowLimit int) (*File, error)
ReadZipWithRowLimit() takes a pointer to a zip.ReadCloser and returns a xlsx.File struct populated with its contents. In most cases ReadZip is not used directly, but is called internally by OpenFile.
func (*File) AddSheet ¶
AddSheet Add a new Sheet, with the provided name, to a File. The minimum sheet name length is 1 character. If the sheet name length is less an error is thrown. The maximum sheet name length is 31 characters. If the sheet name length is exceeded an error is thrown. These special characters are also not allowed: : \ / ? * [ ]
func (*File) AppendSheet ¶
Appends an existing Sheet, with the provided name, to a File
func (*File) MarshallParts ¶
Construct a map of file name to XML content representing the file in terms of the structure of an XLSX file.
func (*File) ToSlice ¶
Return the raw data contained in the File as three dimensional slice. The first index represents the sheet number, the second the row number, and the third the cell number.
For example:
var mySlice [][][]string var value string mySlice = xlsx.FileToSlice("myXLSX.xlsx") value = mySlice[0][0][0]
Here, value would be set to the raw value of the cell A1 in the first sheet in the XLSX file.
func (*File) ToSliceUnmerged ¶
ToSliceUnmerged returns the raw data contained in the File as three dimensional slice (s. method ToSlice). A covered cell become the value of its origin cell. Example: table where A1:A2 merged. | 01.01.2011 | Bread | 20 | | | Fish | 70 | This sheet will be converted to the slice: [ [01.01.2011 Bread 20]
[01.01.2011 Fish 70] ]
type Fill ¶
Fill is a high level structure intended to provide user access to the contents of background and foreground color index within an Sheet.
func DefaultFill ¶
func DefaultFill() *Fill
type Font ¶
type Font struct { Size int Name string Family int Charset int Color string Bold bool Italic bool Underline bool }
func DefaultFont ¶
func DefaultFont() *Font
type HSL ¶
type HSL struct {
H, S, L float64
}
HSL represents a cylindrical coordinate of points in an RGB color model.
Values are in the range 0 to 1.
type RefTable ¶
type RefTable struct {
// contains filtered or unexported fields
}
func MakeSharedStringRefTable ¶
func MakeSharedStringRefTable(source *xlsxSST) *RefTable
MakeSharedStringRefTable() takes an xlsxSST struct and converts it's contents to an slice of strings used to refer to string values by numeric index - this is the model used within XLSX worksheet (a numeric reference is stored to a shared cell value).
func NewSharedStringRefTable ¶
func NewSharedStringRefTable() *RefTable
NewSharedStringRefTable() creates a new, empty RefTable.
func (*RefTable) AddString ¶
AddString adds a string to the reference table and return it's numeric index. If the string already exists then it simply returns the existing index.
func (*RefTable) ResolveSharedString ¶
Resolvesharedstring() looks up a string value by numeric index from a provided reference table (just a slice of strings in the correct order). This function only exists to provide clarity or purpose via it's name.
type Row ¶
type Row struct { Cells []*Cell Hidden bool Sheet *Sheet Height float64 OutlineLevel uint8 // contains filtered or unexported fields }
func (*Row) ReadStruct ¶
ReadStruct reads a struct from r to ptr. Accepts a ptr to struct. This code expects a tag xlsx:"N", where N is the index of the cell to be used. Basic types like int,string,float64 and bool are supported
func (*Row) SetHeightCM ¶
func (*Row) WriteSlice ¶
Writes an array to row r. Accepts a pointer to array type 'e', and writes the number of columns to write, 'cols'. If 'cols' is < 0, the entire array will be written if possible. Returns -1 if the 'e' doesn't point to an array, otherwise the number of columns written.
func (*Row) WriteStruct ¶
Writes a struct to row r. Accepts a pointer to struct type 'e', and the number of columns to write, `cols`. If 'cols' is < 0, the entire struct will be written if possible. Returns -1 if the 'e' doesn't point to a struct, otherwise the number of columns written
type Sheet ¶
type Sheet struct { Name string File *File Rows []*Row Cols []*Col MaxRow int MaxCol int Hidden bool Selected bool SheetViews []SheetView SheetFormat SheetFormat AutoFilter *AutoFilter }
Sheet is a high level structure intended to provide user access to the contents of a particular sheet within an XLSX file.
func (*Sheet) AddRowAtIndex ¶
Add a new Row to a Sheet at a specific index
func (*Sheet) Cell ¶
Get a Cell by passing it's cartesian coordinates (zero based) as row and column integer indexes.
For example:
cell := sheet.Cell(0,0)
... would set the variable "cell" to contain a Cell struct containing the data from the field "A1" on the spreadsheet.
func (*Sheet) RemoveRowAtIndex ¶
Removes a row at a specific index
type SheetFormat ¶
type StreamCell ¶
type StreamCell struct {
// contains filtered or unexported fields
}
StreamCell holds the data, style and type of cell for streaming.
func NewDateStreamCell ¶
func NewDateStreamCell(t time.Time) StreamCell
NewDateStreamCell creates a new cell that holds a date value and is formatted as dd-mm-yyyy and is of type numeric.
func NewIntegerStreamCell ¶
func NewIntegerStreamCell(cellData int) StreamCell
NewIntegerStreamCell creates a new cell that holds an integer value (represented as string), is formatted as a standard integer and is of type numeric.
func NewStreamCell ¶
func NewStreamCell(cellData string, cellStyle StreamStyle, cellType CellType) StreamCell
NewStreamCell creates a new cell containing the given data with the given style and type.
func NewStringStreamCell ¶
func NewStringStreamCell(cellData string) StreamCell
NewStringStreamCell creates a new cell that holds string data, is of type string and uses general formatting.
func NewStyledIntegerStreamCell ¶
func NewStyledIntegerStreamCell(cellData int, cellStyle StreamStyle) StreamCell
NewStyledIntegerStreamCell creates a new cell that holds an integer value (represented as string) and is styled according to the given style.
func NewStyledStringStreamCell ¶
func NewStyledStringStreamCell(cellData string, cellStyle StreamStyle) StreamCell
NewStyledStringStreamCell creates a new cell that holds a string and is styled according to the given style.
type StreamFile ¶
type StreamFile struct {
// contains filtered or unexported fields
}
func (*StreamFile) Close ¶
func (sf *StreamFile) Close() error
Close closes the Stream File. Any sheets that have not yet been written to will have an empty sheet created for them.
func (*StreamFile) Error ¶
func (sf *StreamFile) Error() error
Error reports any error that has occurred during a previous Write or Flush.
func (*StreamFile) Flush ¶
func (sf *StreamFile) Flush()
func (*StreamFile) NextSheet ¶
func (sf *StreamFile) NextSheet() error
NextSheet will switch to the next sheet. Sheets are selected in the same order they were added. Once you leave a sheet, you cannot return to it.
func (*StreamFile) Write ¶
func (sf *StreamFile) Write(cells []string) error
Write will write a row of cells to the current sheet. Every call to Write on the same sheet must contain the same number of cells as the header provided when the sheet was created or an error will be returned. This function will always trigger a flush on success. Currently the only supported data type is string data.
func (*StreamFile) WriteAll ¶
func (sf *StreamFile) WriteAll(records [][]string) error
func (*StreamFile) WriteAllS ¶
func (sf *StreamFile) WriteAllS(records [][]StreamCell) error
WriteAllS will write all the rows provided in records. All rows must have the same number of cells as the number of columns given when creating the sheet. This function will always trigger a flush on success. WriteAllS supports all data types and styles that are supported by StreamCell.
func (*StreamFile) WriteS ¶
func (sf *StreamFile) WriteS(cells []StreamCell) error
WriteS will write a row of cells to the current sheet. Every call to WriteS on the same sheet must contain the same number of cells as the number of columns provided when the sheet was created or an error will be returned. This function will always trigger a flush on success. WriteS supports all data types and styles that are supported by StreamCell.
func (*StreamFile) WriteWithColumnDefaultMetadata ¶
func (sf *StreamFile) WriteWithColumnDefaultMetadata(cells []string) error
WriteWithColumnDefaultMetadata will write a row of cells to the current sheet. Every call to WriteWithColumnDefaultMetadata on the same sheet must contain the same number of cells as the header provided when the sheet was created or an error will be returned. This function will always trigger a flush on success. Each cell will be encoded with the default CellMetadata of the column that it belongs to. However, if the cell data string cannot be parsed into the cell type in CellMetadata, we fall back on encoding the cell as a string and giving it a default string style
type StreamFileBuilder ¶
type StreamFileBuilder struct {
// contains filtered or unexported fields
}
func NewStreamFileBuilder ¶
func NewStreamFileBuilder(writer io.Writer) *StreamFileBuilder
NewStreamFileBuilder creates an StreamFileBuilder that will write to the the provided io.writer
func NewStreamFileBuilderForPath ¶
func NewStreamFileBuilderForPath(path string) (*StreamFileBuilder, error)
NewStreamFileBuilderForPath takes the name of an XLSX file and returns a builder for it. The file will be created if it does not exist, or truncated if it does.
func (*StreamFileBuilder) AddSheet ¶
func (sb *StreamFileBuilder) AddSheet(name string, headers []string, cellTypes []*CellType) error
AddSheet will add sheets with the given name with the provided headers. The headers cannot be edited later, and all rows written to the sheet must contain the same number of cells as the header. Sheet names must be unique, or an error will be thrown.
func (*StreamFileBuilder) AddSheetS ¶
func (sb *StreamFileBuilder) AddSheetS(name string, columnStyles []StreamStyle) error
AddSheetS will add a sheet with the given name and column styles. The number of column styles given is the number of columns that will be created, and thus the number of cells each row has to have. columnStyles[0] becomes the style of the first column, columnStyles[1] the style of the second column etc. All the styles in columnStyles have to have been added or an error will be returned. Sheet names must be unique, or an error will be returned.
func (*StreamFileBuilder) AddSheetWithDefaultColumnMetadata ¶
func (sb *StreamFileBuilder) AddSheetWithDefaultColumnMetadata(name string, headers []string, columnsDefaultCellMetadata []*CellMetadata) error
func (*StreamFileBuilder) AddStreamStyle ¶
func (sb *StreamFileBuilder) AddStreamStyle(streamStyle StreamStyle) error
AddStreamStyle adds a new style to the style sheet. Only Styles that have been added through this function will be usable. This function cannot be used after AddSheetS or Build has been called, and if it is called after AddSheetS or Buildit will return an error.
func (*StreamFileBuilder) AddStreamStyleList ¶
func (sb *StreamFileBuilder) AddStreamStyleList(streamStyles []StreamStyle) error
AddStreamStyleList adds a list of new styles to the style sheet. Only Styles that have been added through either this function or AddStreamStyle will be usable. This function cannot be used after AddSheetS and Build has been called, and if it is called after AddSheetS and Build it will return an error.
func (*StreamFileBuilder) AddValidation ¶
func (sb *StreamFileBuilder) AddValidation(sheetIndex, colIndex, rowStartIndex int, validation *xlsxCellDataValidation)
AddValidation will add a validation to a specific column.
func (*StreamFileBuilder) Build ¶
func (sb *StreamFileBuilder) Build() (*StreamFile, error)
Build begins streaming the XLSX file to the io, by writing all the XLSX metadata. It creates a StreamFile struct that can be used to write the rows to the sheets.
type StreamStyle ¶
type StreamStyle struct {
// contains filtered or unexported fields
}
StreamStyle has style and formatting information. Used to store a style for streaming
var ( StreamStyleFromColumn StreamStyle StreamStyleDefaultString StreamStyle StreamStyleBoldString StreamStyle StreamStyleItalicString StreamStyle StreamStyleUnderlinedString StreamStyle StreamStyleDefaultInteger StreamStyle StreamStyleBoldInteger StreamStyle StreamStyleItalicInteger StreamStyle StreamStyleUnderlinedInteger StreamStyle StreamStyleDefaultDate StreamStyle StreamStyleDefaultDecimal StreamStyle )
func MakeDateStyle ¶
func MakeDateStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle
MakeDateStyle creates a new style that can be used on cells with Date data. The formatting used is: dd_mm_yy If used on other data the formatting might be wrong.
func MakeDecimalStyle ¶
func MakeDecimalStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle
MakeDecimalStyle creates a new style that can be used on cells with decimal numeric data. If used on other data the formatting might be wrong.
func MakeIntegerStyle ¶
func MakeIntegerStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle
MakeIntegerStyle creates a new style that can be used on cells with integer data. If used on other data the formatting might be wrong.
func MakeStringStyle ¶
func MakeStringStyle(font *Font, fill *Fill, alignment *Alignment, border *Border) StreamStyle
MakeStringStyle creates a new style that can be used on cells with string data. If used on other data the formatting might be wrong.
type Style ¶
type Style struct { Border Border Fill Fill Font Font ApplyBorder bool ApplyFill bool ApplyFont bool ApplyAlignment bool Alignment Alignment NamedStyleIndex *int }
Style is a high level structure intended to provide user access to the contents of Style within an XLSX file.
type WorkBookRels ¶
func (*WorkBookRels) MakeXLSXWorkbookRels ¶
func (w *WorkBookRels) MakeXLSXWorkbookRels() xlsxWorkbookRels
type XLSXReaderError ¶
type XLSXReaderError struct {
Err string
}
XLSXReaderError is the standard error type for otherwise undefined errors in the XSLX reading process.
func (*XLSXReaderError) Error ¶
func (e *XLSXReaderError) Error() string
Error returns a string value from an XLSXReaderError struct in order that it might comply with the builtin.error interface.
type XLSXUnmarshaler ¶
XLSXUnmarshaler is the interface implemented for types that can unmarshal a Row as a representation of themselves.
Source Files ¶
- cell.go
- col.go
- data_validation.go
- date.go
- doc.go
- file.go
- format_code.go
- hsl.go
- lib.go
- read.go
- reftable.go
- row.go
- sheet.go
- stream_cell.go
- stream_file.go
- stream_file_builder.go
- stream_style.go
- style.go
- templates.go
- theme.go
- write.go
- xmlContentTypes.go
- xmlSharedStrings.go
- xmlStyle.go
- xmlTheme.go
- xmlWorkbook.go
- xmlWorksheet.go