Documentation ¶
Index ¶
- Constants
- Variables
- func ColIndexToLetters(n int) string
- func ColLettersToIndex(letters string) int
- func DefaultAutoWidth(s string) float64
- func FileToSlice(path string, options ...FileOption) ([][][]string, error)
- func FileToSliceUnmerged(path string, options ...FileOption) ([][][]string, error)
- func GetCellIDStringFromCoords(x, y int) string
- func GetCellIDStringFromCoordsWithFixed(x, y int, xFixed, yFixed bool) string
- func GetCoordsFromCellIDString(cellIDString string) (x, y int, err error)
- func HSLToRGB(h, s, l float64) (r, g, b uint8)
- func MakeDefaultContentTypes() (types xlsxTypes)
- func NewDataValidation(startRow, startCol, endRow, endCol int, allowBlank bool) *xlsxDataValidation
- func RGBToHSL(r, g, b uint8) (h, s, l float64)
- func RowIndexToString(rowRef int) string
- func SetDefaultFont(size float64, name string)
- func SkipEmptyCells(flags *cellVisitorFlags)
- func SkipEmptyRows(flags *rowVisitorFlags)
- func TimeFromExcelTime(excelTime float64, date1904 bool) time.Time
- func TimeToExcelTime(t time.Time, date1904 bool) float64
- func TimeToUTCTime(t time.Time) time.Time
- func UseDiskVCellStore(f *File)
- func UseMemoryCellStore(f *File)
- 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) GetCoordinates() (int, int)
- 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) MarshalBinary() ([]byte, error)
- func (c *Cell) Merge(hcells, vcells int)
- func (c *Cell) Modified() bool
- func (c *Cell) SetBool(b bool)
- func (c *Cell) SetDataValidation(dd *xlsxDataValidation)
- 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) SetHyperlink(hyperlink string, displayText string, tooltip string)
- func (c *Cell) SetInt(n int)
- func (c *Cell) SetInt64(n int64)
- func (c *Cell) SetNumeric(s string)
- func (c *Cell) SetRichText(r []RichTextRun)
- 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
- func (c *Cell) UnmarshalBinary(data []byte) error
- type CellInterface
- type CellStore
- type CellStoreConstructor
- type CellStoreRow
- type CellType
- type CellVisitorFunc
- type CellVisitorOption
- type Col
- type ColStore
- type ColStoreNode
- type DataValidationErrorStyle
- type DataValidationOperator
- type DataValidationType
- type DateTimeOptions
- type DiskVCellStore
- func (cs *DiskVCellStore) Close() error
- func (cs *DiskVCellStore) MakeRow(sheet *Sheet) *Row
- func (cs *DiskVCellStore) MakeRowWithLen(sheet *Sheet, len int) *Row
- func (cs *DiskVCellStore) MoveRow(r *Row, index int) error
- func (cs *DiskVCellStore) ReadRow(key string, s *Sheet) (*Row, error)
- func (cs *DiskVCellStore) RemoveRow(key string) error
- func (cs *DiskVCellStore) WriteRow(r *Row) error
- type DiskVRow
- func (dvr *DiskVRow) AddCell() *Cell
- func (dvr *DiskVRow) CellCount() int
- func (dvr *DiskVRow) CellUpdatable(c *Cell)
- func (dvr *DiskVRow) ForEachCell(cvf CellVisitorFunc, option ...CellVisitorOption) error
- func (dvr *DiskVRow) GetCell(colIdx int) *Cell
- func (dvr *DiskVRow) MaxCol() int
- func (dvr *DiskVRow) PushCell(c *Cell)
- func (dvr *DiskVRow) Updatable()
- type File
- func NewFile(options ...FileOption) *File
- func OpenBinary(bs []byte, options ...FileOption) (*File, error)
- func OpenFile(fileName string, options ...FileOption) (file *File, err error)
- func OpenReaderAt(r io.ReaderAt, size int64, options ...FileOption) (*File, error)
- func ReadZip(f *zip.ReadCloser, options ...FileOption) (*File, error)
- func ReadZipReader(r *zip.Reader, options ...FileOption) (*File, error)
- func (f *File) AddSheet(sheetName string) (*Sheet, error)
- func (f *File) AddSheetWithCellStore(sheetName string, constructor CellStoreConstructor) (*Sheet, error)
- func (f *File) AppendSheet(sheet Sheet, sheetName string) (*Sheet, error)
- func (f *File) MakeStreamParts() (map[string]string, error)
- func (f *File) MarshallParts(zipWriter *zip.Writer) 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) error
- type FileOption
- type Fill
- type Font
- type HSL
- type Hyperlink
- type MemoryCellStore
- func (mcs *MemoryCellStore) Close() error
- func (mcs *MemoryCellStore) MakeRow(sheet *Sheet) *Row
- func (mcs *MemoryCellStore) MakeRowWithLen(sheet *Sheet, len int) *Row
- func (mcs *MemoryCellStore) MoveRow(r *Row, index int) error
- func (mcs *MemoryCellStore) ReadRow(key string, s *Sheet) (*Row, error)
- func (mcs *MemoryCellStore) RemoveRow(key string) error
- func (mcs *MemoryCellStore) WriteRow(r *Row) error
- type MemoryRow
- func (mr *MemoryRow) AddCell() *Cell
- func (mr *MemoryRow) CellCount() int
- func (mr *MemoryRow) CellUpdatable(c *Cell)
- func (mr *MemoryRow) ForEachCell(cvf CellVisitorFunc, option ...CellVisitorOption) error
- func (mr *MemoryRow) GetCell(colIdx int) *Cell
- func (mr *MemoryRow) MaxCol() int
- func (mr *MemoryRow) PushCell(c *Cell)
- func (mr *MemoryRow) Updatable()
- type Pane
- type RefTable
- type Relation
- type RelationshipTargetMode
- type RelationshipType
- type RichTextCharset
- type RichTextColor
- type RichTextFont
- type RichTextFontFamily
- type RichTextRun
- type RichTextUnderline
- type RichTextVertAlign
- type Row
- func (r *Row) AddCell() *Cell
- func (r *Row) ForEachCell(cvf CellVisitorFunc, option ...CellVisitorOption) error
- func (r *Row) GetCell(colIdx int) *Cell
- func (r *Row) GetCoordinate() int
- func (r *Row) GetHeight() float64
- func (r *Row) GetOutlineLevel() uint8
- func (r *Row) PushCell(c *Cell)
- func (r *Row) ReadStruct(ptr interface{}) error
- func (r *Row) SetHeight(ht float64)
- func (r *Row) SetHeightCM(ht float64)
- func (r *Row) SetOutlineLevel(outlineLevel uint8)
- func (r *Row) WriteSlice(e interface{}, cols int) int
- func (r *Row) WriteStruct(e interface{}, cols int) int
- type RowNotFoundError
- type RowVisitor
- type RowVisitorOption
- type Sheet
- func (s *Sheet) AddDataValidation(dv *xlsxDataValidation)
- func (s *Sheet) AddRow() *Row
- func (s *Sheet) AddRowAtIndex(index int) (*Row, error)
- func (s *Sheet) Cell(row, col int) (*Cell, error)
- func (s *Sheet) Close()
- func (s *Sheet) Col(idx int) *Col
- func (s *Sheet) ForEachRow(rv RowVisitor, options ...RowVisitorOption) error
- func (s *Sheet) MarshalSheet(w io.Writer, refTable *RefTable, styles *xlsxStyleSheet, ...) error
- func (s *Sheet) RemoveRowAtIndex(index int) error
- func (s *Sheet) Row(idx int) (*Row, error)
- func (s *Sheet) SetColAutoWidth(colIndex int, width func(string) float64) error
- func (s *Sheet) SetColParameters(col *Col)
- func (s *Sheet) SetColWidth(min, max int, width float64)
- func (s *Sheet) SetOutlineLevel(minCol, maxCol int, outlineLevel uint8)
- func (s *Sheet) SetType(minCol, maxCol int, cellType CellType)
- type SheetFormat
- type SheetView
- type Style
- type WorkBookRels
- type XLSXReaderError
- type XLSXUnmarshaler
Examples ¶
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 ( TRUE = 0x01 FALSE = 0x00 US = 0x1f // Unit Separator RS = 0x1e // Record Separator GS = 0x1d // Group Separator )
const ( // RichTextFontFamilyUnspecified indicates that the font family was not specified RichTextFontFamilyUnspecified RichTextFontFamily = -1 RichTextFontFamilyNotApplicable RichTextFontFamily = 0 RichTextFontFamilyRoman RichTextFontFamily = 1 RichTextFontFamilySwiss RichTextFontFamily = 2 RichTextFontFamilyModern RichTextFontFamily = 3 RichTextFontFamilyScript RichTextFontFamily = 4 RichTextFontFamilyDecorative RichTextFontFamily = 5 // RichTextCharsetUnspecified indicates that the font charset was not specified RichTextCharsetUnspecified RichTextCharset = -1 RichTextCharsetANSI RichTextCharset = 0 RichTextCharsetDefault RichTextCharset = 1 RichTextCharsetSymbol RichTextCharset = 2 RichTextCharsetMac RichTextCharset = 77 RichTextCharsetShiftJIS RichTextCharset = 128 RichTextCharsetHangul RichTextCharset = 129 RichTextCharsetJohab RichTextCharset = 130 RichTextCharsetGB2312 RichTextCharset = 134 RichTextCharsetBIG5 RichTextCharset = 136 RichTextCharsetGreek RichTextCharset = 161 RichTextCharsetTurkish RichTextCharset = 162 RichTextCharsetVietnamese RichTextCharset = 163 RichTextCharsetHebrew RichTextCharset = 177 RichTextCharsetArabic RichTextCharset = 178 RichTextCharsetBaltic RichTextCharset = 186 RichTextCharsetRussian RichTextCharset = 204 RichTextCharsetThai RichTextCharset = 222 RichTextCharsetEastEurope RichTextCharset = 238 RichTextCharsetOEM RichTextCharset = 255 RichTextVertAlignSuperscript RichTextVertAlign = "superscript" RichTextVertAlignSubscript RichTextVertAlign = "subscript" RichTextUnderlineSingle RichTextUnderline = "single" RichTextUnderlineDouble RichTextUnderline = "double" )
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 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 DefaultAutoWidth ¶
This can be use as the default scale function for the autowidth. It works well with the default font sizes.
func FileToSlice ¶
func FileToSlice(path string, options ...FileOption) ([][][]string, error)
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 ¶
func FileToSliceUnmerged(path string, options ...FileOption) ([][][]string, error)
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 NewDataValidation ¶
NewDataValidation return data validation struct
func RowIndexToString ¶
RowIndexToString is used to convert a zero based, numeric row indentifier into its string representation.
func SetDefaultFont ¶
func SkipEmptyCells ¶
func SkipEmptyCells(flags *cellVisitorFlags)
SkipEmptyCells can be passed as an option to Row.ForEachCell in order to make it skip over empty cells in the sheet.
func SkipEmptyRows ¶
func SkipEmptyRows(flags *rowVisitorFlags)
SkipEmptyRows can be passed to the Sheet.ForEachRow function to cause it to skip over empty Rows.
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?
func UseDiskVCellStore ¶
func UseDiskVCellStore(f *File)
UseDiskVCellStore is a FileOption that makes all Sheet instances for a File use DiskV as their backing store. You can use this option when handling very large Sheets that would otherwise riquire allocating vast amounts of memory.
func UseMemoryCellStore ¶
func UseMemoryCellStore(f *File)
UseMemoryCellStore is a FileOption that makes all Sheet instances for a File use memory as their backing store. This is the default backing store. You can use this option when you are comfortable keeping the contents of each Sheet in memory. This is faster than using a disk backed store, but can easily use a large amount of memory and, if you exhaust the available system memory, it'll actualy be slower than using a disk backed store (e.g. DiskV).
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 RichText []RichTextRun NumFmt string Hidden bool HMerge int VMerge int DataValidation *xlsxDataValidation Hyperlink Hyperlink // 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) GetCoordinates ¶
GetCoordinates returns a pair of integers representing the cartesian coorindates of the Cell within the Sheet. The coordinates are zero based and a returned in order x,y where x is the Column number and y is the Row number. If you need to convert these numbers to a Excel cellID (i.e. B15) then please see the GetCellIDStringFromCoords function.
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) MarshalBinary ¶
Return a representation of the Cell as a slice of bytes
func (*Cell) Modified ¶
Modified returns True if a cell has been modified since it was last persisted.
func (*Cell) SetDataValidation ¶
func (c *Cell) SetDataValidation(dd *xlsxDataValidation)
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) SetHyperlink ¶
SetHyperlink sets this cell to contain the given hyperlink, displayText and tooltip. If the displayText or tooltip are an empty string, they will not be set. The hyperlink provided must be a valid URL starting with http:// or https:// or excel will not recognize it as an external link. All other hyperlink formats will be treated as internal link between sheets. Official format in form of `#Sheet!A123`. Maximum number of hyperlinks per sheet is 65530, according to specification.
func (*Cell) SetNumeric ¶
SetNumeric sets a cell's value to a number
func (*Cell) SetRichText ¶
func (c *Cell) SetRichText(r []RichTextRun)
SetRichText sets the value of a cell to a set of the rich text.
func (*Cell) SetStringFormula ¶
func (*Cell) SetValue ¶
func (c *Cell) SetValue(n interface{})
SetInt sets a cell's value to an integer.
func (*Cell) String ¶
String returns the value of a Cell as a string. If you'd like to see errors returned from formatting then please use Cell.FormattedValue() instead.
func (*Cell) UnmarshalBinary ¶
Read a slice of bytes, produced by MarshalBinary, into a Cell
type CellInterface ¶
CellInterface defines the public API of the Cell.
type CellStore ¶
type CellStore interface { MakeRow(sheet *Sheet) *Row MakeRowWithLen(sheet *Sheet, len int) *Row ReadRow(key string, sheet *Sheet) (*Row, error) WriteRow(r *Row) error MoveRow(r *Row, newIndex int) error RemoveRow(key string) error Close() error }
CellStore provides an interface for interacting with backend cell storage. For example, this allows us, as required, to persist cells to some store instead of holding them in memory. This tactic allows us a degree of control around the characteristics of our programs when handling large spreadsheets - we can choose to run more slowly, but without exhausting system memory.
If you wish to implement a custom CellStore you must not only support this interface, but also a CellStoreConstructor and a FileOption that set's the File's cellStoreConstructor to the right constructor.
func NewDiskVCellStore ¶
NewDiskVCellStore is a CellStoreConstructor than returns a CellStore in terms of DiskV.
func NewMemoryCellStore ¶
NewMemoryCellStore returns a pointer to a newly allocated MemoryCellStore
type CellStoreConstructor ¶
CellStoreConstructor defines the signature of a function that will be used to return a new instance of the CellStore implmentation, you must pass this into
type CellStoreRow ¶
type CellStoreRow interface { AddCell() *Cell GetCell(colIdx int) *Cell PushCell(c *Cell) ForEachCell(cvf CellVisitorFunc, option ...CellVisitorOption) error MaxCol() int CellCount() int Updatable() CellUpdatable(c *Cell) }
CellStoreRow is the interface used to interact with the currently loaded Row from the CellStore. Different backends can choose whether to hold the whole row in memory, or persist and load the cell
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 CellVisitorFunc ¶
CellVisitorFunc defines the signature of a function that will be called when visiting a Cell using CellStore.ForEachInRow.
type CellVisitorOption ¶
type CellVisitorOption func(flags *cellVisitorFlags)
CellVisitorOption describes a function that can set values in a cellVisitorFlags struct to affect the way ForEachCell operates
type Col ¶
type Col struct { Min int Max int Hidden *bool Width *float64 Collapsed *bool OutlineLevel *uint8 BestFit *bool CustomWidth *bool Phonetic *bool // contains filtered or unexported fields }
func NewColForRange ¶
NewColForRange return a pointer to a new Col, which will apply to columns in the range min to max (inclusive). Note, in order for this Col to do anything useful you must set some of its parameters and then apply it to a Sheet by calling sheet.SetColParameters.
func (*Col) SetOutlineLevel ¶
type ColStore ¶
type ColStore struct { Root *ColStoreNode Len int }
ColStore is the working store of Col definitions, it will simplify all Cols added to it, to ensure there ar no overlapping definitions.
func (*ColStore) Add ¶
func (cs *ColStore) Add(col *Col) *ColStoreNode
Add a Col to the ColStore. If it overwrites all, or part of some existing Col's range of columns the that Col will be adjusted and/or split to make room for the new Col.
func (*ColStore) FindColByIndex ¶
type ColStoreNode ¶
type ColStoreNode struct { Col *Col Prev *ColStoreNode Next *ColStoreNode }
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 DiskVCellStore ¶
type DiskVCellStore struct {
// contains filtered or unexported fields
}
DiskVCellStore is an implementation of the CellStore interface, backed by DiskV
func (*DiskVCellStore) Close ¶
func (cs *DiskVCellStore) Close() error
Close will remove the persisant storage for a given Sheet completely.
func (*DiskVCellStore) MakeRow ¶
func (cs *DiskVCellStore) MakeRow(sheet *Sheet) *Row
MakeRow returns an empty Row
func (*DiskVCellStore) MakeRowWithLen ¶
func (cs *DiskVCellStore) MakeRowWithLen(sheet *Sheet, len int) *Row
MakeRowWithLen returns an empty Row, with a preconfigured starting length.
func (*DiskVCellStore) MoveRow ¶
func (cs *DiskVCellStore) MoveRow(r *Row, index int) error
MoveRow moves a Row from one position in a Sheet (index) to another within the persistant store.
func (*DiskVCellStore) ReadRow ¶
func (cs *DiskVCellStore) ReadRow(key string, s *Sheet) (*Row, error)
ReadRow reads a row from the persistant store, identified by key, into memory and returns it, with the provided Sheet set as the Row's Sheet.
func (*DiskVCellStore) RemoveRow ¶
func (cs *DiskVCellStore) RemoveRow(key string) error
RemoveRow removes a Row from the Sheet's representation in the persistant store.
func (*DiskVCellStore) WriteRow ¶
func (cs *DiskVCellStore) WriteRow(r *Row) error
WriteRow writes a Row to persistant storage.
type DiskVRow ¶
type DiskVRow struct {
// contains filtered or unexported fields
}
func (*DiskVRow) CellUpdatable ¶
func (*DiskVRow) ForEachCell ¶
func (dvr *DiskVRow) ForEachCell(cvf CellVisitorFunc, option ...CellVisitorOption) error
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 NewFile ¶
func NewFile(options ...FileOption) *File
NewFile creates a new File struct. You may pass it zero, one or many FileOption functions that affect the behaviour of the file.
func OpenBinary ¶
func OpenBinary(bs []byte, options ...FileOption) (*File, error)
OpenBinary() take bytes of an XLSX file and returns a populated xlsx.File struct for it.
func OpenFile ¶
func OpenFile(fileName string, options ...FileOption) (file *File, err error)
OpenFile will take the name of an XLSX file and returns a populated xlsx.File struct for it. You may pass it zero, one or many FileOption functions that affect the behaviour of the file.
func OpenReaderAt ¶
OpenReaderAt() take io.ReaderAt of an XLSX file and returns a populated xlsx.File struct for it.
func ReadZip ¶
func ReadZip(f *zip.ReadCloser, options ...FileOption) (*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 ¶
func ReadZipReader(r *zip.Reader, options ...FileOption) (*File, error)
ReadZipReader() can be used to read an XLSX in memory without touching the filesystem.
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) AddSheetWithCellStore ¶
func (f *File) AddSheetWithCellStore(sheetName string, constructor CellStoreConstructor) (*Sheet, error)
func (*File) AppendSheet ¶
Appends an existing Sheet, with the provided name, to a File
func (*File) MakeStreamParts ¶
MakeStreamParts constructs a map of file name to XML content representing the file in terms of the structure of an XLSX file.
func (*File) MarshallParts ¶
MarshallParts constructs 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 FileOption ¶
type FileOption func(f *File)
func RowLimit ¶
func RowLimit(n int) FileOption
RowLimit will limit the rows handled in any given sheet to the first n, where n is the number of rows.
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 float64 Name string Family int Charset int Color string Bold bool Italic bool Underline bool Strike 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 Hyperlink ¶
Hyperlink is a structure to store link information in-workbook links to cells or defined names are stored in Location external links are stores in Link
type MemoryCellStore ¶
type MemoryCellStore struct {
// contains filtered or unexported fields
}
MemoryCellStore is the default CellStore - it holds all rows and cells in system memory. This is fast, right up until you run out of memory ;-)
func (*MemoryCellStore) Close ¶
func (mcs *MemoryCellStore) Close() error
Close is nullOp for the MemoryCellStore, but we have to comply with the interface.
func (*MemoryCellStore) MakeRow ¶
func (mcs *MemoryCellStore) MakeRow(sheet *Sheet) *Row
MakeRow returns an empty Row
func (*MemoryCellStore) MakeRowWithLen ¶
func (mcs *MemoryCellStore) MakeRowWithLen(sheet *Sheet, len int) *Row
MakeRowWithLen returns an empty Row, with a preconfigured starting length.
func (*MemoryCellStore) MoveRow ¶
func (mcs *MemoryCellStore) MoveRow(r *Row, index int) error
MoveRow moves the persisted Row's position in the sheet.
func (*MemoryCellStore) ReadRow ¶
func (mcs *MemoryCellStore) ReadRow(key string, s *Sheet) (*Row, error)
ReadRow returns a Row identfied by the given key.
func (*MemoryCellStore) RemoveRow ¶
func (mcs *MemoryCellStore) RemoveRow(key string) error
RemoveRow removes a row from the sheet, it doesn't specifically move any following rows, leaving this decision to the user.
func (*MemoryCellStore) WriteRow ¶
func (mcs *MemoryCellStore) WriteRow(r *Row) error
WriteRow pushes the Row to the MemoryCellStore.
type MemoryRow ¶
type MemoryRow struct {
// contains filtered or unexported fields
}
func (*MemoryRow) CellUpdatable ¶
func (*MemoryRow) ForEachCell ¶
func (mr *MemoryRow) ForEachCell(cvf CellVisitorFunc, option ...CellVisitorOption) error
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) AddRichText ¶
func (rt *RefTable) AddRichText(r []RichTextRun) int
AddRichText adds a set of rich text to the reference table and return it's numeric index. If a set of rich text already exists then it simply returns the existing index.
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 ¶
func (rt *RefTable) ResolveSharedString(index int) (plainText string, richText []RichTextRun)
ResolveSharedString looks up a string value or the rich text by numeric index from a provided reference table (just a slice of strings in the correct order). If the rich text was found, non-empty slice will be returned in richText. This function only exists to provide clarity of purpose via it's name.
type Relation ¶
type Relation struct { Type RelationshipType Target string TargetMode RelationshipTargetMode }
type RelationshipTargetMode ¶
type RelationshipTargetMode string
const (
RelationshipTargetModeExternal RelationshipTargetMode = "External"
)
type RelationshipType ¶
type RelationshipType string
const (
RelationshipTypeHyperlink RelationshipType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
)
type RichTextCharset ¶
type RichTextCharset int
type RichTextColor ¶
type RichTextColor struct {
// contains filtered or unexported fields
}
RichTextColor is the color of the RichTextRun.
func NewRichTextColorFromARGB ¶
func NewRichTextColorFromARGB(alpha, red, green, blue int) *RichTextColor
NewRichTextColorFromARGB creates a new RichTextColor from ARGB component values. Each component must have a value in range of 0 to 255.
func NewRichTextColorFromThemeColor ¶
func NewRichTextColorFromThemeColor(themeColor int) *RichTextColor
NewRichTextColorFromThemeColor creates a new RichTextColor from the theme color. The argument `themeColor` is a zero-based index of the theme color.
type RichTextFont ¶
type RichTextFont struct { // Name is the font name. If Name is empty, Size, Family and Charset will be ignored. Name string // Size is the font size. Size float64 // Family is a value of the font family. Use one of the RichTextFontFamily constants. Family RichTextFontFamily // Charset is a value of the charset of the font. Use one of the RichTextCharset constants. Charset RichTextCharset // Color is the text color. Color *RichTextColor // Bold specifies the bold face font style. Bold bool // Italic specifies the italic font style. Italic bool // Strike specifies a strikethrough line. Strike bool // VertAlign specifies the vertical position of the text. Use one of the RichTextVertAlign constants, or empty. VertAlign RichTextVertAlign // Underline specifies the underline style. Use one of the RichTextUnderline constants, or empty. Underline RichTextUnderline }
RichTextFont is the font spec of the RichTextRun.
type RichTextFontFamily ¶
type RichTextFontFamily int
type RichTextRun ¶
type RichTextRun struct { Font *RichTextFont Text string }
RichTextRun is a run of the decorated text.
func (*RichTextRun) Equals ¶
func (rt *RichTextRun) Equals(other *RichTextRun) bool
type RichTextUnderline ¶
type RichTextUnderline string
type RichTextVertAlign ¶
type RichTextVertAlign string
type Row ¶
type Row struct { Hidden bool // Hidden determines whether this Row is hidden or not. Sheet *Sheet // Sheet is a reference back to the Sheet that this Row is within. // contains filtered or unexported fields }
Row represents a single Row in the current Sheet.
func (*Row) ForEachCell ¶
func (r *Row) ForEachCell(cvf CellVisitorFunc, option ...CellVisitorOption) error
ForEachCell will call the provided CellVisitorFunc for each currently defined cell in the Row. Optionally you may pass one or more CellVisitorOption to affect how ForEachCell operates. For example you may wish to pass SkipEmptyCells to only visit cells which are populated.
func (*Row) GetCell ¶
GetCell returns the Cell at a given column index, creating it if it doesn't exist.
func (*Row) GetCoordinate ¶
GetCoordinate returns the y coordinate of the row (the row number). This number is zero based, i.e. the Excel CellID "A1" is in Row 0, not Row 1.
func (*Row) GetOutlineLevel ¶
GetOutlineLevel returns the outline level of the Row.
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
Example ¶
//example type type structTest struct { IntVal int `xlsx:"0"` StringVal string `xlsx:"1"` FloatVal float64 `xlsx:"2"` IgnoredVal int `xlsx:"-"` BoolVal bool `xlsx:"4"` } structVal := structTest{ IntVal: 16, StringVal: "heyheyhey :)!", FloatVal: 3.14159216, IgnoredVal: 7, BoolVal: true, } //create a new xlsx file and write a struct //in a new row f := NewFile() sheet, _ := f.AddSheet("TestRead") row := sheet.AddRow() row.WriteStruct(&structVal, -1) //read the struct from the same row readStruct := &structTest{} err := row.ReadStruct(readStruct) if err != nil { panic(err) } fmt.Println(readStruct)
Output:
func (*Row) SetHeightCM ¶
SetHeightCM sets the height of the Row in centimetres, inherently converting it to PostScript points.
func (*Row) SetOutlineLevel ¶
SetOutlineLevel sets the outline level of the Row (used for collapsing rows)
func (*Row) WriteSlice ¶
Writes a slice to row r. Accepts a slice or a pointer to a slice, and will wirte up to the provided number of columns, 'cols'. If 'cols' is < 0, the entire slice will be written if possible. Returns -1 if the 'e' is not a slice type, 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 RowNotFoundError ¶
type RowNotFoundError struct {
// contains filtered or unexported fields
}
RowNotFoundError is an Error that should be returned by a RowStore implementation if a call to ReadRow is made with a key that doesn't correspond to any persisted Row.
func NewRowNotFoundError ¶
func NewRowNotFoundError(key, reason string) *RowNotFoundError
NewRowNotFoundError creates a new RowNotFoundError, capturing the Row key and the reason this key could not be found.
func (RowNotFoundError) Error ¶
func (cnfe RowNotFoundError) Error() string
Error returns a human-readable description of the failure to find a Row. It makes RowNotFoundError comply with the Error interface.
type RowVisitor ¶
A RowVisitor function should be provided by the user when calling Sheet.ForEachRow, it will be called once for every Row visited.
type RowVisitorOption ¶
type RowVisitorOption func(flags *rowVisitorFlags)
RowVisitorOption defines the call signature of functions that can be passed as options to the Sheet.ForEachRow function to affect its behaviour.
type Sheet ¶
type Sheet struct { Name string File *File Cols *ColStore MaxRow int MaxCol int Hidden bool Selected bool SheetViews []SheetView SheetFormat SheetFormat AutoFilter *AutoFilter Relations []Relation DataValidations []*xlsxDataValidation // contains filtered or unexported fields }
Sheet is a high level structure intended to provide user access to the contents of a particular sheet within an XLSX file.
func NewSheetWithCellStore ¶
func NewSheetWithCellStore(name string, constructor CellStoreConstructor) (*Sheet, error)
NewSheetWithCellStore constructs a Sheet, backed by a CellStore, for which you must provide the constructor function.
func (*Sheet) AddDataValidation ¶
func (s *Sheet) AddDataValidation(dv *xlsxDataValidation)
Add a DataValidation to a range of cells
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) Close ¶
func (s *Sheet) Close()
Remove Sheet's dependant resources - if you are done with operations on a sheet this should be called to clear down the Sheet's persistent cache. Note: if you call this, all further read operaton on the sheet will fail - including any attempt to save the file, or dump it's contents to a byte stream. Therefore only call this *after* you've saved your changes, of when you're done reading a sheet in a file you don't plan to persist.
func (*Sheet) Col ¶
Return the Col that applies to this Column index, or return nil if no such Col exists
func (*Sheet) ForEachRow ¶
func (s *Sheet) ForEachRow(rv RowVisitor, options ...RowVisitorOption) error
func (*Sheet) MarshalSheet ¶
func (*Sheet) RemoveRowAtIndex ¶
Removes a row at a specific index
func (*Sheet) SetColAutoWidth ¶
Tries to guess the best width for a column, based on the largest cell content. A scale function needs to be provided.
func (*Sheet) SetColParameters ¶
Set the parameters of a column. Parameters are passed as a pointer to a Col structure which you much construct yourself.
func (*Sheet) SetColWidth ¶
Set the width of a range of columns.
func (*Sheet) SetOutlineLevel ¶
Set the outline level for a range of columns.
type SheetFormat ¶
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
- cellstore.go
- col.go
- data_validation.go
- date.go
- diskv.go
- doc.go
- file.go
- format_code.go
- hsl.go
- lib.go
- memory.go
- read.go
- reftable.go
- richtext.go
- row.go
- sheet.go
- style.go
- templates.go
- testutil.go
- theme.go
- utility.go
- write.go
- xmlContentTypes.go
- xmlSharedStrings.go
- xmlStyle.go
- xmlTheme.go
- xmlWorkbook.go
- xmlWorksheet.go