Documentation
¶
Overview ¶
xls package use to parse the 97 -2004 microsoft xls file(".xls" suffix, NOT ".xlsx" suffix )
there are some example in godoc, please follow them.
Index ¶
- Constants
- Variables
- func ErrorText(code int) string
- func IsDateFormatString(format string) bool
- func JulianDateToGregorianTime(part1, part2 float64) time.Time
- func TimeFromExcelTime(excelTime float64, date1904 bool) time.Time
- type BlankCol
- type Cell
- type CellRange
- type Col
- type Coler
- type Font
- type FontInfo
- type Format
- type FormulaCol
- type FormulaStringCol
- type HyperLink
- type LabelsstCol
- type MulBlankCol
- type MulrkCol
- type NumberCol
- type RK
- type Ranger
- type RkCol
- type Row
- type SstInfo
- type TWorkSheetVisibility
- type WorkBook
- func (w *WorkBook) DateMode() uint16
- func (w *WorkBook) FormatIndexForXf(xf int) uint16
- func (w *WorkBook) FormatText(no uint16) string
- func (w *WorkBook) GetSheet(num int) *WorkSheet
- func (w *WorkBook) IsDate(formatNo uint16) bool
- func (w *WorkBook) NumSheets() int
- func (w *WorkBook) Parse(buf io.ReadSeeker)
- func (w *WorkBook) ReadAllCells(max int) (res [][]string)
- func (w *WorkBook) TypedCell(sheet, row, col int) Cell
- type WorkSheet
- type Xf5
- type Xf8
- type XfRk
Examples ¶
Constants ¶
const MJD_0 float64 = 2400000.5
const MJD_JD2000 float64 = 51544.5
Variables ¶
var ErrIsInt = fmt.Errorf("is int")
Functions ¶
func ErrorText ¶
ErrorText renders an Excel error code the way xlrd's error_text_from_code does, so both sides produce the same string for an error cell.
func IsDateFormatString ¶ added in v0.1.1
IsDateFormatString applies xlrd's format-string rule: whether a number-format string denotes a date. It is exported because the rule is usable on its own — IsDate reaches it only for a workbook whose format record it can read.
func JulianDateToGregorianTime ¶ added in v0.1.1
JulianDateToGregorianTime converts a Julian date to a time.Time. The two parts are summed before conversion, so the day number and the fraction of a day may be passed separately. The MJD constants above are its usual inputs.
func TimeFromExcelTime ¶ added in v0.1.1
TimeFromExcelTime converts an Excel serial date — the floating-point number a spreadsheet stores for a date — into a time.Time. date1904 selects the workbook's date system; WorkBook.DateMode reports it.
Types ¶
type Cell ¶
type Cell struct {
Present bool
Kind string // number | text | bool | error | blank
Number float64
Text string
Bool bool
Error int
FormatNo uint16
}
Cell is one cell's value with the format index the date rule needs.
type FormulaCol ¶
type FormulaCol struct {
Header struct {
Col
IndexXf uint16
Result [8]byte
Flags uint16
// contains filtered or unexported fields
}
Bts []byte
}
func (*FormulaCol) Cached ¶
func (c *FormulaCol) Cached() (value interface{}, kind string)
Cached decodes the result a FORMULA record carries: the value Excel last computed for the formula, which is what a reader has to report for a formula cell (the formula itself is not evaluated). Mirrors xlrd's handling — the last two bytes being 0xFFFF mark a non-numeric result, selected by the first byte; otherwise the eight bytes are an IEEE double.
kind is "number", "bool", "error", "text" or "blank". A string result is not available here: it arrives in the STRING record that follows, which the parser turns into a FormulaStringCol at the same cell.
func (*FormulaCol) FirstCol ¶
func (c *FormulaCol) FirstCol() uint16
func (*FormulaCol) LastCol ¶
func (c *FormulaCol) LastCol() uint16
func (*FormulaCol) Row ¶
func (c *FormulaCol) Row() uint16
func (*FormulaCol) String ¶
func (c *FormulaCol) String(wb *WorkBook) []string
type FormulaStringCol ¶
func (*FormulaStringCol) String ¶
func (c *FormulaStringCol) String(wb *WorkBook) []string
type HyperLink ¶
type HyperLink struct {
CellRange
Description string
TextMark string
TargetFrame string
Url string
ShortedFilePath string
ExtendedFilePath string
IsUrl bool
}
hyperlink type's content
type LabelsstCol ¶
func (*LabelsstCol) String ¶
func (c *LabelsstCol) String(wb *WorkBook) []string
type MulBlankCol ¶
func (*MulBlankCol) LastCol ¶
func (c *MulBlankCol) LastCol() uint16
func (*MulBlankCol) String ¶
func (c *MulBlankCol) String(wb *WorkBook) []string
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row the data of one row
func (*Row) Col ¶
Col Get the Nth Col from the Row, if has not, return nil. Suggest use Has function to test it.
func (*Row) ColExact ¶
ColExact Get the Nth Col from the Row, if has not, return nil. For merged cells value is returned for first cell only
type TWorkSheetVisibility ¶
type TWorkSheetVisibility byte
const ( WorkSheetVisible TWorkSheetVisibility = 0 WorkSheetHidden TWorkSheetVisibility = 1 WorkSheetVeryHidden TWorkSheetVisibility = 2 )
type WorkBook ¶
type WorkBook struct {
Is5ver bool
Type uint16
Codepage uint16
Xfs []st_xf_data
Fonts []Font
Formats map[uint16]*Format
Author string
// contains filtered or unexported fields
}
xls workbook type
func Open ¶
Open one xls file
Example ¶
if xlFile, err := Open("Table.xls"); err == nil {
fmt.Println(xlFile.Author)
}
func OpenReader ¶
func OpenReader(reader io.ReadSeeker) (wb *WorkBook, err error)
Open xls file from reader
There is no charset argument: the old one was inert. It was passed straight to ole2.Open, whose source mentions it exactly once — as the parameter name — so any value at all behaved identically. What actually decides how text is decoded is the workbook's own CODEPAGE record, read at workbook.go:87 and consumed by get_string.
func OpenWithCloser ¶
Open one xls file and return the closer
func (*WorkBook) FormatIndexForXf ¶
FormatIndexForXf returns the format index behind an XF index.
func (*WorkBook) FormatText ¶
FormatText returns the format string behind a format index, or "".
func (*WorkBook) GetSheet ¶
Get one sheet by its number
Example ¶
Output: read the content of first two cols in each row
if xlFile, err := Open("Table.xls"); err == nil {
if sheet1 := xlFile.GetSheet(0); sheet1 != nil {
fmt.Print("Total Lines ", sheet1.MaxRow, sheet1.Name)
col1 := sheet1.Row(0).Col(0)
col2 := sheet1.Row(0).Col(0)
for i := 0; i <= (int(sheet1.MaxRow)); i++ {
row1 := sheet1.Row(i)
col1 = row1.Col(0)
col2 = row1.Col(1)
fmt.Print("\n", col1, ",", col2)
}
}
}
func (*WorkBook) IsDate ¶
IsDate decides whether a cell with this format index is a date, by xlrd's rule: a format record's string decides when the workbook carries one, and the built-in table is the fallback for a key with no record.
func (*WorkBook) NumSheets ¶
Get the number of all sheets, look into example
Example ¶
if xlFile, err := Open("Table.xls"); err == nil {
for i := 0; i < xlFile.NumSheets(); i++ {
sheet := xlFile.GetSheet(i)
fmt.Println(sheet.Name)
}
}
func (*WorkBook) Parse ¶
func (w *WorkBook) Parse(buf io.ReadSeeker)
func (*WorkBook) ReadAllCells ¶
helper function to read all cells from file Notice: the max value is the limit of the max capacity of lines. Warning: the helper function will need big memeory if file is large.
type WorkSheet ¶
type WorkSheet struct {
Name string
Selected bool
Visibility TWorkSheetVisibility
//NOTICE: this is the max row number of the sheet, so it should be count -1
MaxRow uint16
// contains filtered or unexported fields
}
WorkSheet in one WorkBook
func (*WorkSheet) MaxCol ¶ added in v0.1.1
MaxCol reports the largest column index that carries a cell anywhere in the sheet, so the number of columns is MaxCol()+1 — the same "count - 1" convention MaxRow uses. It returns -1 when the sheet carries no cells, which makes MaxCol()+1 the column count in that case too.
The value is derived from the cell records, not from the row records. A ROW record may declare extents wider than the cells it actually holds, and xlrd's ncols — which this mirrors — is computed from the cells as it reads them.