workbook

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: GPL-3.0, LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package workbook opens and parses an .xlsb workbook file (a ZIP archive).

Index

Constants

View Source
const (
	// SheetVisible indicates the sheet tab is visible (hsState == 0).
	SheetVisible = 0
	// SheetHidden indicates the sheet is hidden but can be unhidden by the
	// user via Excel's "Unhide" dialog (hsState == 1).
	SheetHidden = 1
	// SheetVeryHidden indicates the sheet is hidden and cannot be unhidden
	// through the Excel UI — only via VBA or programmatic access (hsState == 2).
	SheetVeryHidden = 2
)

Sheet visibility levels, as stored in the hsState field of a BrtBundleSh record (MS-XLSB §2.4.720). Use these constants with SheetVisibility.

Variables

This section is empty.

Functions

This section is empty.

Types

type Workbook

type Workbook struct {

	// Styles is the full XF style table parsed from xl/styles.bin.  It is
	// exported so that callers who need low-level access to format metadata
	// can inspect it directly; normal callers should use FormatCell.
	Styles styles.StyleTable
	// Date1904 is true when the workbook uses the 1904 date system (base
	// date 1904-01-01, serial 0 = 1904-01-01). Most workbooks use the
	// default 1900 system (Date1904 == false). Pass this value to
	// ConvertDateEx when converting numeric cell values to time.Time.
	Date1904 bool
	// contains filtered or unexported fields
}

Workbook represents an open .xlsb workbook.

func Open

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

Open opens the named .xlsb file and parses its workbook metadata. The caller must call Close on the returned Workbook when done to release the underlying file handle.

func OpenReader

func OpenReader(r io.ReaderAt, size int64) (*Workbook, error)

OpenReader parses an .xlsb workbook from an in-memory ReaderAt. size must be the total byte size of the ZIP data.

func (*Workbook) Close

func (wb *Workbook) Close() error

Close releases the underlying ZIP file handle. It is a no-op when the workbook was opened via OpenReader (no file handle to release), and always returns nil in that case.

func (*Workbook) FormatCell added in v1.1.0

func (wb *Workbook) FormatCell(v any, styleIdx int) string

FormatCell renders the cell value v using the XF style at index styleIdx. Pass cell.V as v and cell.Style as styleIdx.

The returned string is the same display string that Excel would show in the cell. Use this alongside Rows() to get both the raw value (cell.V) and the formatted display string:

for row := range sheet.Rows(false) {
    for _, cell := range row {
        raw       := cell.V
        formatted := wb.FormatCell(cell.V, cell.Style)
        _ = raw
        _ = formatted
    }
}

When styleIdx is out of range (e.g. because styles.bin was absent), the function falls back to fmt.Sprint(v).

func (*Workbook) Sheet

func (wb *Workbook) Sheet(idx int) (*worksheet.Worksheet, error)

Sheet returns the worksheet at the given 1-based index. Index 1 refers to the first sheet. An out-of-range index returns a non-nil error describing the valid range.

func (*Workbook) SheetByName

func (wb *Workbook) SheetByName(name string) (*worksheet.Worksheet, error)

SheetByName returns the worksheet with the given name (case-insensitive). It returns a non-nil error if no sheet with that name exists.

func (*Workbook) SheetVisibility added in v1.1.0

func (wb *Workbook) SheetVisibility(name string) int

SheetVisibility returns the visibility level of the named sheet (case-insensitive): SheetVisible (0), SheetHidden (1), or SheetVeryHidden (2). It returns -1 if no sheet with that name exists.

func (*Workbook) SheetVisible added in v1.1.0

func (wb *Workbook) SheetVisible(name string) bool

SheetVisible reports whether the named sheet is visible (case-insensitive). It returns false for hidden sheets, very-hidden sheets, and unknown names. To distinguish hidden from very-hidden, use SheetVisibility.

func (*Workbook) Sheets

func (wb *Workbook) Sheets() []string

Sheets returns the display names of all worksheets in order.

Jump to

Keyboard shortcuts

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