xls

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 12 Imported by: 0

README

xls

Go License GoDoc Tag

纯 Go XLS 解析库。轻量、高效、零依赖、无 CGo。

安装

go get github.com/wsyqn6/xls

使用

package main

import "github.com/wsyqn6/xls"

func main() {
    wb, _ := xls.Open("example.xls")
    for _, sh := range wb.Sheets() {
        for _, r := range sh.Rows() {
            for _, c := range r.Cells() {
                // c.Type(), c.Col(), c.Value()
            }
        }
    }
}

开发

go build ./...
go test ./...
go vet ./...

License

MIT


xls

Go License GoDoc Tag

Pure Go XLS parser. Lightweight, efficient, zero dependencies, no CGo.

Installation

go get github.com/wsyqn6/xls

Usage

package main

import "github.com/wsyqn6/xls"

func main() {
    wb, _ := xls.Open("example.xls")
    for _, sh := range wb.Sheets() {
        for _, r := range sh.Rows() {
            for _, c := range r.Cells() {
                // c.Type(), c.Col(), c.Value()
            }
        }
    }
}

Development

go build ./...
go test ./...
go vet ./...

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	// contains filtered or unexported fields
}

Cell represents a single cell.

func (*Cell) AsBool

func (c *Cell) AsBool() (bool, bool)

AsBool returns the boolean value and true if the cell is a boolean.

func (*Cell) AsNumber

func (c *Cell) AsNumber() (float64, bool)

AsNumber returns the numeric value and true if the cell is a number.

func (*Cell) AsString

func (c *Cell) AsString() (string, bool)

AsString returns the string value and true if the cell is a string.

func (*Cell) Bool

func (c *Cell) Bool() bool

Bool returns the boolean value.

func (*Cell) Col

func (c *Cell) Col() int

Col returns the column index.

func (*Cell) ColumnName

func (c *Cell) ColumnName() string

ColumnName returns the Excel column name (A, B, ..., Z, AA, AB).

func (*Cell) IsEmpty

func (c *Cell) IsEmpty() bool

IsEmpty reports whether the cell is empty.

func (*Cell) Number

func (c *Cell) Number() float64

Number returns the numeric value.

func (*Cell) String

func (c *Cell) String() string

func (*Cell) Time

func (c *Cell) Time() (time.Time, bool)

Time returns the cell value as a time.Time for date-formatted numbers.

func (*Cell) Type

func (c *Cell) Type() CellType

Type returns the cell type.

func (*Cell) Value

func (c *Cell) Value() string

Value returns the cell value as a string.

type CellRef

type CellRef struct {
	Row int
	Col int
}

CellRef identifies a cell position.

type CellType

type CellType uint8

CellType classifies a cell's value.

const (
	CellEmpty  CellType = 0
	CellNumber CellType = 1
	CellString CellType = 2
	CellBool   CellType = 3
	CellError  CellType = 4
)

func (CellType) String

func (ct CellType) String() string

type Row

type Row struct {
	// contains filtered or unexported fields
}

Row represents a row in a worksheet.

func (*Row) Cell

func (r *Row) Cell(col int) *Cell

Cell returns a cell by column index.

func (*Row) Cells

func (r *Row) Cells() iter.Seq2[int, *Cell]

Cells returns an iterator over cells.

func (*Row) NumCells

func (r *Row) NumCells() int

NumCells returns the number of cells in the row.

type Sheet

type Sheet struct {
	// contains filtered or unexported fields
}

Sheet represents a worksheet.

func (*Sheet) Cells

func (s *Sheet) Cells() iter.Seq2[CellRef, *Cell]

Cells returns a flat iterator over all cells in the sheet.

func (*Sheet) Dimension

func (s *Sheet) Dimension() (firstRow, lastRow, firstCol, lastCol int, ok bool)

Dimension returns the sheet dimension bounds (inclusive). ok is false when no data or dimension is unavailable.

func (*Sheet) Name

func (s *Sheet) Name() string

Name returns the sheet name.

func (*Sheet) NumRows

func (s *Sheet) NumRows() int

NumRows returns the number of rows.

func (*Sheet) Row

func (s *Sheet) Row(i int) *Row

Row returns a row by index.

func (*Sheet) RowByNumber

func (s *Sheet) RowByNumber(n int) *Row

RowByNumber returns a row by its Excel row number, or nil if not found.

func (*Sheet) Rows

func (s *Sheet) Rows() iter.Seq2[int, *Row]

Rows returns an iterator over rows.

type Workbook

type Workbook struct {
	// contains filtered or unexported fields
}

Workbook represents an XLS workbook.

func Open

func Open(name string) (*Workbook, error)

Open reads an XLS file.

func OpenReader

func OpenReader(r io.ReadSeeker) (*Workbook, error)

OpenReader reads an XLS file from a ReadSeeker.

func (*Workbook) DateMode

func (wb *Workbook) DateMode() int

DateMode returns the date mode: 0 = 1900, 1 = 1904.

func (*Workbook) NumSheets

func (wb *Workbook) NumSheets() int

NumSheets returns the number of sheets.

func (*Workbook) Sheet

func (wb *Workbook) Sheet(i int) (*Sheet, error)

Sheet returns a sheet by index.

func (*Workbook) Sheets

func (wb *Workbook) Sheets() iter.Seq2[int, *Sheet]

Sheets returns an iterator over sheets.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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