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 ByteToUint16(b []byte) uint16
- func ByteToUint32(b []byte) uint32
- type BlankCol
- type CellRange
- type Col
- type Coler
- type ExtSheetInfo
- type Font
- type FontInfo
- type Format
- type FormulaCol
- type FormulaColHeader
- 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 XF
- type Xf5
- type Xf8
- type XfRk
Examples ¶
Constants ¶
const MS_BIFF_CRYPTO_NONE = 0
Encryption type
const MS_BIFF_CRYPTO_RC4 = 2
const MS_BIFF_CRYPTO_XOR = 1
const REKEY_BLOCK = 0x400
Size of stream blocks when using RC4 encryption
const TYPE_BOOL = 5
const TYPE_CURRENCY = 11
const TYPE_DATETIME = 9
const TYPE_ERROR = 8
const TYPE_FORMULA = 3
const TYPE_INLINE = 7
const TYPE_NULL = 6
const TYPE_NUMERIC = 4
const TYPE_PERCENTAGE = 10
const TYPE_STRING = 2
const TYPE_STRING2 = 1
Data types
const XLS_BIFF7 = 0x0500
const XLS_BIFF8 = 0x0600
ParseXL definitions
const XLS_Type_ARRAY = 0x0221
const XLS_Type_BLANK = 0x0201
const XLS_Type_BOF = 0x0809
const XLS_Type_BOOLERR = 0x0205
const XLS_Type_BOTTOMMARGIN = 0x0029
const XLS_Type_CODEPAGE = 0x0042
const XLS_Type_COLINFO = 0x007d
const XLS_Type_CONTINUE = 0x003c
const XLS_Type_DATAVALIDATION = 0x01be
const XLS_Type_DATAVALIDATIONS = 0x01b2
const XLS_Type_DATEMODE = 0x0022
const XLS_Type_DBCELL = 0x00d7
const XLS_Type_DEFAULTROWHEIGHT = 0x0225
const XLS_Type_DEFCOLWIDTH = 0x0055
const XLS_Type_DEFINEDNAME = 0x0018
const XLS_Type_DIMENSION = 0x0200
const XLS_Type_EOF = 0x000a
const XLS_Type_EXTERNALBOOK = 0x01ae
const XLS_Type_EXTERNNAME = 0x0023
const XLS_Type_EXTERNSHEET = 0x0017
const XLS_Type_EXTSST = 0x00ff
const XLS_Type_FILEPASS = 0x002f
const XLS_Type_FONT = 0x0031
const XLS_Type_FOOTER = 0x0015
const XLS_Type_FORMAT = 0x041e
const XLS_Type_FORMULA = 0x0006
record identifiers
const XLS_Type_HCENTER = 0x0083
const XLS_Type_HEADER = 0x0014
const XLS_Type_HORIZONTALPAGEBREAKS = 0x001b
const XLS_Type_HYPERLINK = 0x01b8
const XLS_Type_IMDATA = 0x007f
const XLS_Type_INDEX = 0x020b
const XLS_Type_LABEL = 0x0204
const XLS_Type_LABELSST = 0x00fd
const XLS_Type_LEFTMARGIN = 0x0026
const XLS_Type_MERGEDCELLS = 0x00e5
const XLS_Type_MSODRAWING = 0x00ec
const XLS_Type_MSODRAWINGGROUP = 0x00eb
const XLS_Type_MULBLANK = 0x00be
const XLS_Type_MULRK = 0x00bd
const XLS_Type_NOTE = 0x001c
const XLS_Type_NUMBER = 0x0203
const XLS_Type_OBJ = 0x005d
const XLS_Type_OBJECTPROTECT = 0x0063
const XLS_Type_PAGELAYOUTVIEW = 0x088b
const XLS_Type_PAGESETUP = 0x00a1
const XLS_Type_PALETTE = 0x0092
const XLS_Type_PANE = 0x0041
const XLS_Type_PASSWORD = 0x0013
const XLS_Type_PRINTGRIDLINES = 0x002b
const XLS_Type_PROTECT = 0x0012
const XLS_Type_RANGEPROTECTION = 0x0868
const XLS_Type_RIGHTMARGIN = 0x0027
const XLS_Type_RK = 0x027e
const XLS_Type_ROW = 0x0208
const XLS_Type_SCENPROTECT = 0x00dd
const XLS_Type_SCL = 0x00a0
const XLS_Type_SELECTION = 0x001d
const XLS_Type_SHAREDFMLA = 0x04bc
const XLS_Type_SHEET = 0x0085
const XLS_Type_SHEETLAYOUT = 0x0862
const XLS_Type_SHEETPR = 0x0081
const XLS_Type_SHEETPROTECTION = 0x0867
const XLS_Type_SST = 0x00fc
const XLS_Type_STRING = 0x0207
const XLS_Type_STYLE = 0x0293
const XLS_Type_TOPMARGIN = 0x0028
const XLS_Type_TXO = 0x01b6
const XLS_Type_UNKNOWN = 0xffff
const XLS_Type_VCENTER = 0x0084
const XLS_Type_VERTICALPAGEBREAKS = 0x001a
const XLS_Type_WINDOW2 = 0x023e
const XLS_Type_XF = 0x00e0
const XLS_Type_XFEXT = 0x087d
const XLS_WorkbookGlobals = 0x0005
const XLS_Worksheet = 0x0010
Variables ¶
var ErrIsInt = errors.New("is int")
Functions ¶
func ByteToUint16 ¶ added in v0.0.2
ByteToUint16 Read 16-bit unsigned integer
func ByteToUint32 ¶ added in v0.0.2
ByteToUint32 Read 32-bit unsigned integer
Types ¶
type ExtSheetInfo ¶ added in v0.0.2
ExtSheetInfo external sheet references provided for named cells
type Format ¶
type Format struct { Head struct { Index uint16 Size uint16 } Raw []string // contains filtered or unexported fields }
Format value interface
type FormulaCol ¶
type FormulaCol struct { Code uint16 Btl uint16 Btc uint16 Bts []byte Header *FormulaColHeader // contains filtered or unexported fields }
func (*FormulaCol) Debug ¶ added in v0.0.2
func (c *FormulaCol) Debug(wb *WorkBook)
func (*FormulaCol) FirstCol ¶ added in v0.0.2
func (c *FormulaCol) FirstCol() uint16
func (*FormulaCol) LastCol ¶ added in v0.0.2
func (c *FormulaCol) LastCol() uint16
func (*FormulaCol) Row ¶ added in v0.0.2
func (c *FormulaCol) Row() uint16
func (*FormulaCol) String ¶
func (c *FormulaCol) String(wb *WorkBook) []string
type FormulaColHeader ¶ added in v0.0.2
type FormulaColHeader struct { Col IndexXf uint16 Result [8]byte Flags uint16 // contains filtered or unexported fields }
func (*FormulaColHeader) IsPart ¶ added in v0.0.2
func (f *FormulaColHeader) IsPart() bool
IsPart part of shared formula check WARNING: We can apparently not rely on $isPartOfSharedFormula. Even when $isPartOfSharedFormula = true the formula data may be ordinary formula data, therefore we need to check explicitly for the tExp token (0x01)
func (*FormulaColHeader) Value ¶ added in v0.0.2
func (f *FormulaColHeader) Value() float64
Value formula header value
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) Debug ¶ added in v0.0.2
func (c *LabelsstCol) Debug(wb *WorkBook)
func (*LabelsstCol) String ¶
func (c *LabelsstCol) String(wb *WorkBook) []string
type MulBlankCol ¶
func (*MulBlankCol) Debug ¶ added in v0.0.2
func (c *MulBlankCol) Debug(wb *WorkBook)
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 { Debug bool Is5ver bool Type uint16 Codepage uint16 Xfs []XF Fonts []Font Formats map[uint16]*Format Author string // contains filtered or unexported fields }
WorkBook excel work book
func Open ¶
Open one xls file
Example ¶
if xlFile, err := Open("Table.xls", "utf-8"); err == nil { fmt.Println(xlFile.Author) }
Output:
func OpenReader ¶
func OpenReader(reader io.ReadSeeker, charset string) (wb *WorkBook, err error)
OpenReader open xls file from reader
func OpenWithBuffer ¶ added in v0.0.2
OpenWithBuffer open one xls file with memory buffer
func OpenWithCloser ¶ added in v0.0.2
OpenWithCloser open one xls file and return the closer
func (*WorkBook) GetSheet ¶
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", "utf-8"); 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) } } }
Output:
func (*WorkBook) ReadAllCells ¶
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 memory if file is large.
func (*WorkBook) SetFloatBit ¶ added in v0.0.2
SetFloatBit 设置小数默认保留位数,默认值 -1 不限制
type WorkSheet ¶
type WorkSheet struct { Name string Selected bool MaxRow uint16 // contains filtered or unexported fields }
WorkSheet in one WorkBook
func (*WorkSheet) GetSheetVisible ¶ added in v0.0.2
GetSheetVisible provides a function to get worksheet visible