xlsx

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ColWidth = 9.5

Default column width in excel

View Source
const MJD_0 float64 = 2400000.5
View Source
const MJD_JD2000 float64 = 51544.5
View Source
const TEMPLATE_DOCPROPS_APP = `` /* 308-byte string literal not displayed */
View Source
const TEMPLATE_DOCPROPS_CORE = `` /* 364-byte string literal not displayed */
View Source
const TEMPLATE_XL_THEME_THEME = `` /* 10942-byte string literal not displayed */
View Source
const TEMPLATE__RELS_DOT_RELS = `` /* 580-byte string literal not displayed */

Variables

View Source
var HSLModel = color.ModelFunc(hslModel)

HSLModel converts any color.Color to a HSL color.

Functions

func FileToSlice

func FileToSlice(path string) ([][][]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 HSLToRGB

func HSLToRGB(h, s, l float64) (r, g, b uint8)

HSLToRGB converts an HSL triple to a RGB triple.

Ported from http://goo.gl/Vg1h9

func MakeDefaultContentTypes

func MakeDefaultContentTypes() (types xlsxTypes)

func RGBToHSL

func RGBToHSL(r, g, b uint8) (h, s, l float64)

RGBToHSL converts an RGB triple to a HSL triple.

Ported from http://goo.gl/Vg1h9

func SetDefaultFont

func SetDefaultFont(size int, name string)

func TimeFromExcelTime

func TimeFromExcelTime(excelTime float64, date1904 bool) time.Time

Convert an excelTime representation (stored as a floating point number) to a time.Time.

Types

type Alignment

type Alignment struct {
	Horizontal string
	Vertical   string
}

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

func NewBorder

func NewBorder(left, right, top, bottom string) *Border

type Cell

type Cell struct {
	Row   *Row
	Value string

	NumFmt string

	Hidden bool
	HMerge int
	VMerge int
	// 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 NewCell

func NewCell(r *Row) *Cell

NewCell creates a cell and adds it to a row.

func (*Cell) Bool

func (c *Cell) Bool() 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) Float

func (c *Cell) Float() (float64, error)

Float returns the value of cell as a number.

func (*Cell) FormattedValue

func (c *Cell) FormattedValue() string

FormattedValue returns the formatted version of the value. If it's a string type, c.Value will just be returned. Otherwise, it will attempt to apply Excel formatting to the value.

func (*Cell) Formula

func (c *Cell) Formula() string

Formula returns the formula string for the cell.

func (*Cell) GetNumberFormat

func (c *Cell) GetNumberFormat() string

GetNumberFormat returns the number format string for a cell.

func (*Cell) GetStyle

func (c *Cell) GetStyle() *Style

GetStyle returns the Style associated with a Cell

func (*Cell) Int

func (c *Cell) Int() (int, error)

Int returns the value of cell as integer. Has max 53 bits of precision See: float64(int64(math.MaxInt))

func (*Cell) Int64

func (c *Cell) Int64() (int64, error)

Int64 returns the value of cell as 64-bit integer.

func (*Cell) Merge

func (c *Cell) Merge(hcells, vcells int)

Merge with other cells, horizontally and/or vertically.

func (*Cell) SafeFormattedValue

func (c *Cell) SafeFormattedValue() (string, error)

SafeFormattedValue 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) SetBool

func (c *Cell) SetBool(b bool)

SetBool sets a cell's value to a boolean.

func (*Cell) SetDate

func (c *Cell) SetDate(t time.Time)

SetDate sets the value of a cell to a float.

func (*Cell) SetDateTime

func (c *Cell) SetDateTime(t time.Time)

func (*Cell) SetDateTimeWithFormat

func (c *Cell) SetDateTimeWithFormat(n float64, format string)

func (*Cell) SetFloat

func (c *Cell) SetFloat(n float64)

SetFloat sets the value of a cell to a float.

func (*Cell) SetFloatWithFormat

func (c *Cell) SetFloatWithFormat(n float64, format string)

SetFloatWithFormat sets the value of a cell to a float and applies formatting to the cell.

func (*Cell) SetFormula

func (c *Cell) SetFormula(formula string)

SetFormula sets the format string for a cell.

func (*Cell) SetInt

func (c *Cell) SetInt(n int)

SetInt sets a cell's value to an integer.

func (*Cell) SetInt64

func (c *Cell) SetInt64(n int64)

SetInt64 sets a cell's value to a 64-bit integer.

func (*Cell) SetString

func (c *Cell) SetString(s string)

SetString sets the value of a cell to a string.

func (*Cell) SetStyle

func (c *Cell) SetStyle(style *Style)

SetStyle sets the style of a cell.

func (*Cell) SetValue

func (c *Cell) SetValue(n interface{})

SetInt sets a cell's value to an integer.

func (*Cell) String

func (c *Cell) String() string

String returns the value of a Cell as a string.

func (*Cell) Type

func (c *Cell) Type() CellType

Type returns the CellType of a cell. See CellType constants for more details.

type CellInterface

type CellInterface interface {
	String() string
	FormattedValue() string
}

CellInterface defines the public API of 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
	CellTypeFormula
	CellTypeNumeric
	CellTypeBool
	CellTypeInline
	CellTypeError
	CellTypeDate
	CellTypeGeneral
)

Known types for cell values.

type Col

type Col struct {
	Min       int
	Max       int
	Hidden    bool
	Width     float64
	Collapsed bool
	// contains filtered or unexported fields
}

func (*Col) GetStyle

func (c *Col) GetStyle() *Style

GetStyle returns the Style associated with a Col

func (*Col) SetStyle

func (c *Col) SetStyle(style *Style)

SetStyle sets the style of a Col

func (*Col) SetType

func (c *Col) SetType(cellType CellType)

type File

type File struct {
	Date1904 bool

	Sheets []*Sheet
	Sheet  map[string]*Sheet
	// contains filtered or unexported fields
}

File is a high level structure providing a slice of Sheet structs to the user.

func NewFile

func NewFile() (file *File)

Create a new File

func OpenBinary

func OpenBinary(bs []byte) (file *File, err error)

OpenBinary() take bytes of an XLSX file and returns a populated xlsx.File struct for it.

func OpenFile

func OpenFile(filename string) (file *File, err error)

OpenFile() take the name of an XLSX file and returns a populated xlsx.File struct for it.

func OpenReaderAt

func OpenReaderAt(r io.ReaderAt, size int64) (file *File, err error)

OpenReaderAt() 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

func ReadZipReader(r *zip.Reader) (*File, error)

ReadZipReader() can be used to read an XLSX in memory without touching the filesystem.

func (*File) AddSheet

func (f *File) AddSheet(sheetName string) (sheet *Sheet, err error)

Add a new Sheet, with the provided name, to a File

func (*File) MarshallParts

func (f *File) MarshallParts() (map[string]string, error)

Construct a map of file name to XML content representing the file in terms of the structure of an XLSX file.

func (*File) Save

func (f *File) Save(path string) (err error)

Save the File to an xlsx file at the provided path.

func (*File) ToSlice

func (file *File) ToSlice() (output [][][]string, err error)

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) Write

func (f *File) Write(writer io.Writer) (err error)

Write the File to io.Writer as xlsx

type Fill

type Fill struct {
	PatternType string
	BgColor     string
	FgColor     string
}

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

func NewFill

func NewFill(patternType, fgColor, bgColor string) *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

func NewFont

func NewFont(size int, name string) *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.

func (HSL) RGBA

func (c HSL) RGBA() (uint32, uint32, uint32, uint32)

RGBA returns the alpha-premultiplied red, green, blue and alpha values for the HSL.

type Pane

type Pane struct {
	XSplit      float64
	YSplit      float64
	TopLeftCell string
	ActivePane  string
	State       string // Either "split" or "frozen"
}

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

func (rt *RefTable) AddString(str string) int

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) Length

func (rt *RefTable) Length() int

func (*RefTable) ResolveSharedString

func (rt *RefTable) ResolveSharedString(index int) string

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
	// contains filtered or unexported fields
}

func (*Row) AddCell

func (r *Row) AddCell() *Cell

func (*Row) SetHeightCM

func (r *Row) SetHeightCM(ht float64)

func (*Row) WriteSlice

func (r *Row) WriteSlice(e interface{}, cols int) int

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

func (r *Row) WriteStruct(e interface{}, cols int) int

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
}

Sheet is a high level structure intended to provide user access to the contents of a particular sheet within an XLSX file.

func (*Sheet) AddRow

func (s *Sheet) AddRow() *Row

Add a new Row to a Sheet

func (*Sheet) Cell

func (sh *Sheet) Cell(row, col int) *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) Col

func (s *Sheet) Col(idx int) *Col

Make sure we always have as many Cols as we do cells.

func (*Sheet) SetColWidth

func (s *Sheet) SetColWidth(startcol, endcol int, width float64) error

Set the width of a single column or multiple columns.

type SheetFormat

type SheetFormat struct {
	DefaultColWidth  float64
	DefaultRowHeight float64
}

type SheetView

type SheetView struct {
	Pane *Pane
}

type Style

type Style struct {
	Border         Border
	Fill           Fill
	Font           Font
	ApplyBorder    bool
	ApplyFill      bool
	ApplyFont      bool
	ApplyAlignment bool
	Alignment      Alignment
}

Style is a high level structure intended to provide user access to the contents of Style within an XLSX file.

func NewStyle

func NewStyle() *Style

Return a new Style structure initialised with the default values.

type WorkBookRels

type WorkBookRels map[string]string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL