xls

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

XLS Reader

This is derived from: https://github.com/extrame/xls

WARNING

Neither this package, nor the package this is derived from, should be considered production worthy. There are tests that do not pass for good reasons.

While I believe this is an improvment (you can close files), it still has issues.

Documentation

Overview

Package xls reads binary XLS files.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrIsInt = fmt.Errorf("is int")

Functions

This section is empty.

Types

type BlankCol

type BlankCol struct {
	Col
	Xf uint16
}

func (*BlankCol) String

func (c *BlankCol) String(wb *WorkBook) []string

func (*BlankCol) Value

func (c *BlankCol) Value(wb *WorkBook) CellValue

type CellRange

type CellRange struct {
	FirstRowB uint16
	LastRowB  uint16
	FristColB uint16
	LastColB  uint16
}

range type of multi cells in multi rows

func (*CellRange) FirstCol

func (c *CellRange) FirstCol() uint16

func (*CellRange) FirstRow

func (c *CellRange) FirstRow() uint16

func (*CellRange) LastCol

func (c *CellRange) LastCol() uint16

func (*CellRange) LastRow

func (c *CellRange) LastRow() uint16

type CellValue

type CellValue struct {
	Text   string
	Float  float64
	Int    int64
	Format string
}

type Col

type Col struct {
	RowB      uint16
	FirstColB uint16
}

func (*Col) FirstCol

func (c *Col) FirstCol() uint16

func (*Col) LastCol

func (c *Col) LastCol() uint16

func (*Col) Row

func (c *Col) Row() uint16

func (*Col) String

func (c *Col) String(wb *WorkBook) []string

type Font

type Font struct {
	Info *FontInfo
	Name string
}

type FontInfo

type FontInfo struct {
	Height     uint16
	Flag       uint16
	Color      uint16
	Bold       uint16
	Escapement uint16
	Underline  byte
	Family     byte
	Charset    byte
	Notused    byte
	NameB      byte
}

type Format

type Format struct {
	Head struct {
		Index uint16
		Size  uint16
	}
	// contains filtered or unexported fields
}

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

func (*FormulaCol) Value

func (c *FormulaCol) Value(wb *WorkBook) CellValue

type FormulaStringCol

type FormulaStringCol struct {
	Col
	RenderedValue string
}

func (*FormulaStringCol) String

func (c *FormulaStringCol) String(wb *WorkBook) []string

func (*FormulaStringCol) Value

func (c *FormulaStringCol) Value(wb *WorkBook) CellValue
type HyperLink struct {
	CellRange
	Description      string
	TextMark         string
	TargetFrame      string
	URL              string
	ShortedFilePath  string
	ExtendedFilePath string
	IsURL            bool
}

HyperLink of a link.

func (*HyperLink) String

func (h *HyperLink) String(wb *WorkBook) []string

get the hyperlink string, use the public variable Url to get the original Url

func (*HyperLink) Value

func (h *HyperLink) Value(wb *WorkBook) CellValue

type LabelsstCol

type LabelsstCol struct {
	Col
	Xf  uint16
	Sst uint32
}

func (*LabelsstCol) String

func (c *LabelsstCol) String(wb *WorkBook) []string

func (*LabelsstCol) Value

func (c *LabelsstCol) Value(wb *WorkBook) CellValue

type MulBlankCol

type MulBlankCol struct {
	Col
	Xfs      []uint16
	LastColB uint16
}

func (*MulBlankCol) LastCol

func (c *MulBlankCol) LastCol() uint16

func (*MulBlankCol) String

func (c *MulBlankCol) String(wb *WorkBook) []string

func (*MulBlankCol) Value

func (c *MulBlankCol) Value(wb *WorkBook) CellValue

type MulrkCol

type MulrkCol struct {
	Col
	Xfrks    []XfRk
	LastColB uint16
}

func (*MulrkCol) LastCol

func (c *MulrkCol) LastCol() uint16

func (*MulrkCol) String

func (c *MulrkCol) String(wb *WorkBook) []string

func (*MulrkCol) Value

func (c *MulrkCol) Value(wb *WorkBook) CellValue

type NumberCol

type NumberCol struct {
	Col
	Index uint16
	Float float64
}

func (*NumberCol) String

func (c *NumberCol) String(wb *WorkBook) []string

func (*NumberCol) Value

func (c *NumberCol) Value(wb *WorkBook) CellValue

type RK

type RK uint32

func (RK) Float

func (rk RK) Float() (float64, error)

func (RK) String

func (rk RK) String() string

func (RK) Value

func (rk RK) Value(wb *WorkBook) CellValue

type Ranger

type Ranger interface {
	FirstRow() uint16
	LastRow() uint16
}

range type of multi rows

type RkCol

type RkCol struct {
	Col
	Xfrk XfRk
}

func (*RkCol) String

func (c *RkCol) String(wb *WorkBook) []string

func (*RkCol) Value

func (c *RkCol) Value(wb *WorkBook) CellValue

type Row

type Row struct {
	Cols map[uint16]contentHandler
	// contains filtered or unexported fields
}

Row handle.

func (*Row) Col

func (r *Row) Col(n int) string

Col gets the n'th column (zero-based). If not found it will return empty string. Merged cells will be reported more then once if iterating.

func (*Row) ColExact

func (r *Row) ColExact(n int) string

ColExact gets the n'th column (zero-based). If not found it will return empty string. Merged cells will only show the value at the first cell.

func (*Row) FirstCol

func (r *Row) FirstCol() int

FirstCol gets the index of the first column.

func (*Row) LastCol

func (r *Row) LastCol() int

LastCol gets the index of the last column.

func (*Row) Value

func (r *Row) Value(n int) CellValue

Value of the cell.

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
	XF       []XF
	Fonts    []Font
	Formats  map[uint16]*Format

	Author string
	// contains filtered or unexported fields
}

WorkBook is the parsed XLS file.

func Open

func Open(name, charset string) (*WorkBook, error)

Open a XLS file from disk with the given charset.

Example
xlFile, err := Open(filepath.Join("testdata", "table.xls"), "utf-8")
if err != nil {
	log.Fatal(err)
}
defer xlFile.Close()

fmt.Println(xlFile.Author)
Output:

func OpenReader

func OpenReader(r io.ReadSeeker, charset string) (*WorkBook, error)

OpenReader opens an XLS file from r with charset. Charset may be "utf-8". If r is a closer, r.Close will be called when WorkBook.Close is called.

func (*WorkBook) Close

func (w *WorkBook) Close() error

Close WorkBook if it was opened with a Closer.

func (*WorkBook) GetSheet

func (w *WorkBook) GetSheet(num int) (*WorkSheet, error)

GetSheet gets one sheet by its number.

func (*WorkBook) NumSheets

func (w *WorkBook) NumSheets() int

NumSheets gets the number of all sheets, look into example.

func (*WorkBook) ReadAll

func (w *WorkBook) ReadAll(max int) (res [][]string)

ReadAll is a 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.

func (*WorkBook) ToDateTime

func (wb *WorkBook) ToDateTime(f float64) time.Time

type WorkSheet

type WorkSheet struct {
	Name       string
	Selected   bool
	Visibility TWorkSheetVisibility
	Rows       map[uint16]*Row
	//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) Row

func (w *WorkSheet) Row(i int) *Row

type XF

type XF interface {
	// contains filtered or unexported methods
}

type XfRk

type XfRk struct {
	Index uint16
	Rk    RK
}

func (*XfRk) String

func (xf *XfRk) String(wb *WorkBook) string

func (*XfRk) Value

func (xf *XfRk) Value(wb *WorkBook) CellValue

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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