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
- type BlankCol
- type CellRange
- type Col
- type Coler
- type Font
- type FontInfo
- type Format
- type FormulaCol
- type HyperLink
- type LabelsstCol
- type MulBlankCol
- type MulrkCol
- type NumberCol
- type RK
- type Ranger
- type RkCol
- type Row
- type SstInfo
- type WorkBook
- 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")
var ErrNoDirectory = errors.New("xls: compound file header declares no directory stream")
ErrNoDirectory reports a header whose directory stream begins at the end-of-chain sentinel, so the container declares no directory at all.
The container reader underneath builds its directory entries by walking that chain and then indexes the first entry unconditionally, so an empty walk leaves it indexing an empty slice. Rejecting here converts a panic into an error, and cannot reject anything that reads: a container with no directory has nowhere to keep a workbook stream.
var ErrNoWorkbookStream = errors.New("xls: compound file holds no workbook stream")
ErrNoWorkbookStream reports a compound file that holds no stream a workbook can be read from: no directory entry reachable from the root is named "Workbook" (BIFF8) or "Book" (BIFF5). A container whose directory entries exist but are not linked into its directory tree reaches this.
var ErrShortHeader = errors.New("xls: input is shorter than a compound file header")
ErrShortHeader reports input too short to hold a compound file header. It is a permanent property of the input, not a transient read failure: a caller that retries on io.EOF must not retry this, so it deliberately does not wrap io.EOF.
Functions ¶
This section is empty.
Types ¶
type FormulaCol ¶
type FormulaCol struct {
Header struct {
Col
IndexXf uint16
Result [8]byte
Flags uint16
// contains filtered or unexported fields
}
Bts []byte
}
func (*FormulaCol) String ¶
func (c *FormulaCol) 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.
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 ¶
OpenReader reads a workbook from a compound file.
The charset parameter both of these used to take is gone. It was never read: the container layer it was handed to ignored it, and the BIFF layer carries its own encoding logic, so it had been inert since before this fork. It survived earlier revisions of this change on the grounds that dropping a parameter breaks published callers for nothing — an argument that stops applying in the one release where the signature is already breaking.
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) 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
//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