xlwt

package module
v0.0.0-...-99e6795 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: LGPL-2.1 Imports: 6 Imported by: 0

README

xlwt-go

A Go library for writing Microsoft Excel (.xls) files. Ported from the Python xlwt library.

Install

go get github.com/LaoQi/xlwt-go

Usage

package main

import (
	"log"
	"os"

	xlwt "github.com/LaoQi/xlwt-go"
)

func main() {
	wb := xlwt.NewWorkbook()
	ws := wb.AddSheet("Sheet1")

	ws.Write(0, 0, "Hello, XLS!")

	fp, err := os.Create("output.xls")
	if err != nil {
		log.Fatal(err)
	}
	defer fp.Close()

	if err := wb.Save(fp); err != nil {
		log.Fatal(err)
	}
}

Limitations

  • Only supports string cells
  • No style customization
  • No formula support
  • No number/date cell types

License

LGPL-2.1

Documentation

Index

Constants

View Source
const (
	// stream types
	Biff8BOFRecord__BOOK_GLOBAL = 0x0005
	Biff8BOFRecord__VB_MODULE   = 0x0006
	Biff8BOFRecord__WORKSHEET   = 0x0010
	Biff8BOFRecord__CHART       = 0x0020
	Biff8BOFRecord__MACROSHEET  = 0x0040
	Biff8BOFRecord__WORKSPACE   = 0x0100
)
View Source
const CONTINUE_ID = 0x003C
View Source
const DefaultCellXFStyle = 0x11
View Source
const DefaultRowHeightOptions = 0x00FF & 0x07FFF
View Source
const FIRST_USER_DEFINED_NUM_FORMAT_IDX = 164
View Source
const MIN_LIMIT = 0x1000
View Source
const MaxSSTCellLength = 0x2000
View Source
const MaxSSTLength = 0x2020
View Source
const SECTOR_SIZE = 0x0200
View Source
const SID_END_OF_CHAIN = -2
View Source
const SID_FREE_SECTOR = -1
View Source
const SID_USED_BY_MSAT = -4
View Source
const SID_USED_BY_SAT = -3

Variables

View Source
var SP_H_0 = []byte{0x00, 0x00}
View Source
var SP_H_1 = []byte{0x01, 0x00}
View Source
var StdNumFormatString = []string{
	"general",
	"0",
	"0.00",
	"#,##0",
	"#,##0.00",
	"\"$\"#,##0_);(\"$\"#,##0)",
	"\"$\"#,##0_);[Red](\"$\"#,##0)",
	"\"$\"#,##0.00_);(\"$\"#,##0.00)",
	"\"$\"#,##0.00_);[Red](\"$\"#,##0.00)",
	"0%",
	"0.00%",
	"0.00E+00",
	"# ?/?",
	"# ??/??",
	"M/D/YY",
	"D-MMM-YY",
	"D-MMM",
	"MMM-YY",
	"h:mm AM/PM",
	"h:mm:ss AM/PM",
	"h:mm",
	"h:mm:ss",
	"M/D/YY h:mm",
}

Functions

func ASCIIStringPack

func ASCIIStringPack(s string) []byte

func ASCIIStringPack2

func ASCIIStringPack2(s string) []byte

func BackupRecord

func BackupRecord(_ int) []byte

BackupRecord backup int

func Biff8BOFRecord

func Biff8BOFRecord(recType SP_H) []byte

func BlankRecord

func BlankRecord(row int, col int, xfIDX int) []byte

func BookBoolRecord

func BookBoolRecord() []byte

func BottomMarginRecord

func BottomMarginRecord(arg1 float64) []byte

func BoundSheetRecord

func BoundSheetRecord(streamPos int, visibility int, sheet string) []byte

func CalcCountRecord

func CalcCountRecord(calcCount int) []byte

func CalcModeRecord

func CalcModeRecord(calcMode int) []byte

func CellXFRecord

func CellXFRecord(fontIdx int) []byte

func CodepageBiff8Record

func CodepageBiff8Record() []byte

func DSFRecord

func DSFRecord() []byte

func DateModeRecord

func DateModeRecord(from1904 bool) []byte

func DefaultCellXFRecord

func DefaultCellXFRecord() []byte

func DefaultFontRecord

func DefaultFontRecord() []byte

func DefaultRowHeightRecord

func DefaultRowHeightRecord(options, defHeight int) []byte

func DefaultWindow2Record

func DefaultWindow2Record() []byte

func DefaultXFRecord

func DefaultXFRecord() []byte

func DeltaRecord

func DeltaRecord(delta float64) []byte

func DimensionsRecord

func DimensionsRecord(firstUsedRow, lastUsedRow, firstUsedCol, lastUsedCol int) []byte

func EOFRecord

func EOFRecord() []byte

func FillBytes

func FillBytes(size int, value byte) []byte

func FillInt

func FillInt(size int, value int) []int

func FnGroupCountRecord

func FnGroupCountRecord() []byte

func FooterRecord

func FooterRecord(footerStr string) []byte

func GridSetRecord

func GridSetRecord(arg1 int) []byte

func GutsRecord

func GutsRecord(rowGutWidth, colGutHeight, rowVisibleLevels, colVisibleLevels int) []byte

func HCenterRecord

func HCenterRecord(arg1 int) []byte

func HeaderRecord

func HeaderRecord(headerStr string) []byte

func HideObjRecord

func HideObjRecord() []byte

func HorizontalPageBreaksRecord

func HorizontalPageBreaksRecord() []byte

func InteraceEndRecord

func InteraceEndRecord() []byte

func InteraceHdrRecord

func InteraceHdrRecord() []byte

func IterationRecord

func IterationRecord(iterationsOn int) []byte

func LabelSSTRecord

func LabelSSTRecord(row int, col int, xfIDX int, sstIDX int) []byte

func LeftMarginRecord

func LeftMarginRecord(arg1 float64) []byte

func MMSRecord

func MMSRecord() []byte

func NumberFormatRecord

func NumberFormatRecord(idx int, str string) []byte

func ObjectProtectRecord

func ObjectProtectRecord(objprotect int) []byte

func PaletteRecord

func PaletteRecord() []byte

func PasswordRecord

func PasswordRecord(_ string) []byte

func PrecisionRecord

func PrecisionRecord(use_real_values bool) []byte

func PrintGridLinesRecord

func PrintGridLinesRecord(arg1 int) []byte

func PrintHeadersRecord

func PrintHeadersRecord(printHeaders int) []byte

func Prot4RevPassRecord

func Prot4RevPassRecord() []byte

func Prot4RevRecord

func Prot4RevRecord() []byte

func ProtectRecord

func ProtectRecord(protect int) []byte

func RefModeRecord

func RefModeRecord(refMode int) []byte

func RefreshAllRecord

func RefreshAllRecord() []byte

func RightMarginRecord

func RightMarginRecord(arg1 float64) []byte

func RowRecord

func RowRecord(index, firstCol, lastCol, heightOptions, options int) []byte

func SaveRecalcRecord

func SaveRecalcRecord(recalc int) []byte

func ScenProtectRecord

func ScenProtectRecord(arg1 int) []byte

func SetupPageRecord

func SetupPageRecord() []byte

func SingleHRecord

func SingleHRecord(RecID int, hNum int) []byte

func StyleRecord

func StyleRecord() []byte

func TabIDRecord

func TabIDRecord(sheetCount int) []byte

func TopMarginRecord

func TopMarginRecord(arg1 float64) []byte

func U16StringPack

func U16StringPack(s string) []byte

func UseSelfsRecord

func UseSelfsRecord() []byte

func VCenterRecord

func VCenterRecord(arg1 int) []byte

func VerticalPageBreaksRecord

func VerticalPageBreaksRecord() []byte

func WSBoolRecord

func WSBoolRecord(options int) []byte

func Window1Record

func Window1Record() []byte

func Window2Record

func Window2Record(options, firstVisibleRow, firstVisibleCol, gridColour, previewMagn, normalMagn int) []byte

func WindowProtectRecord

func WindowProtectRecord(wndprotect int) []byte

func WriteAccessRecord

func WriteAccessRecord(owner []byte) []byte

Types

type BiffRecord

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

func NewBiffRecord

func NewBiffRecord(RecID SP_H, RecData []byte) *BiffRecord

func (*BiffRecord) Get

func (r *BiffRecord) Get() []byte

func (*BiffRecord) GetRecHeader

func (r *BiffRecord) GetRecHeader() []byte

type Cell

type Cell struct {
	Row    int
	Col    int
	SSTIdx int
	XFIdx  int
}

type SP_B

type SP_B uint8 // struct.pack('<B')

type SP_H

type SP_H uint16 // struct.pack('<H')

type SP_I

type SP_I uint32 // struct.pack('<I')

type SP_L

type SP_L uint32 // struct.pack('<L')

type SP_d

type SP_d float64 // struct.pack('<d')

type SP_h

type SP_h int16 // struct.pack('<h')

type SP_l

type SP_l int32 // struct.pack('<l')

type SharedStringTable

type SharedStringTable struct {
	StrIndexes map[string]int
	StrList    []string
	Total      int
}

func NewSharedStringTable

func NewSharedStringTable() *SharedStringTable

func (*SharedStringTable) AddStr

func (sst *SharedStringTable) AddStr(value string) int

func (*SharedStringTable) GetBiffRecord

func (sst *SharedStringTable) GetBiffRecord() []byte

type Workbook

type Workbook struct {
	Owner      string
	Worksheets []*Worksheet
	SST        *SharedStringTable
	Style      *XFStyle
}

func NewWorkbook

func NewWorkbook() *Workbook

func (*Workbook) AddSheet

func (wb *Workbook) AddSheet(name string) *Worksheet

func (*Workbook) AddStyle

func (wb *Workbook) AddStyle(s *XFStyle)

func (*Workbook) BoundsSheetsRec

func (wb *Workbook) BoundsSheetsRec(start int, sheetsLen []int) []byte

func (*Workbook) GetBiffData

func (wb *Workbook) GetBiffData() []byte

func (*Workbook) Save

func (wb *Workbook) Save(writer io.Writer) error

type Worksheet

type Worksheet struct {
	Name      string
	SST       *SharedStringTable
	Grid      map[uint32]Cell
	RowsIndex map[int]bool
}

func NewWorksheet

func NewWorksheet(name string, sst *SharedStringTable) *Worksheet

func (*Worksheet) GetBiffData

func (ws *Worksheet) GetBiffData() []byte

func (*Worksheet) GetRowCellsBiffData

func (ws *Worksheet) GetRowCellsBiffData(row int) []byte

func (*Worksheet) GetRowsBiffData

func (ws *Worksheet) GetRowsBiffData() []byte

func (*Worksheet) GutsRec

func (ws *Worksheet) GutsRec() []byte

func (*Worksheet) Write

func (ws *Worksheet) Write(r, c int, label string)

type XFStyle

type XFStyle struct {
}

func (*XFStyle) GetBiffData

func (xf *XFStyle) GetBiffData() []byte

type XlsDoc

type XlsDoc struct {
	SAT_sect []int

	MSAT_sect_2nd []int
	// contains filtered or unexported fields
}

func NewXlsDoc

func NewXlsDoc() *XlsDoc

func (*XlsDoc) BuildDirectory

func (xls *XlsDoc) BuildDirectory()

func (*XlsDoc) BuildSat

func (xls *XlsDoc) BuildSat()

func (*XlsDoc) Save

func (xls *XlsDoc) Save(writer io.Writer, stream []byte) error

func (*XlsDoc) WriteHeader

func (xls *XlsDoc) WriteHeader()

Jump to

Keyboard shortcuts

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