spreadsheet

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package spreadsheet owns the SpreadsheetML (XLSX) conventions shared by datatable exports and imports: cell references, OOXML text escapes and serial dates. It performs no I/O.

Index

Constants

View Source
const (
	// MaxRows and MaxColumns are the worksheet dimensions of the format.
	MaxRows    = 1_048_576
	MaxColumns = 16_384
	// MaxCellUTF16Units is the text length limit of one cell.
	MaxCellUTF16Units = 32_767
	// ExactDigits is the precision spreadsheets store and display exactly.
	ExactDigits = 15
)
View Source
const LocalDateTimeLayout = "2006-01-02T15:04:05.999999999"

LocalDateTimeLayout is the wall-clock text layout of LocalDateTime values.

Variables

This section is empty.

Functions

func AppendColumn

func AppendColumn(dst []byte, n int) []byte

AppendColumn appends the column letters of 1-based index n (1 is A).

func AppendText

func AppendText(dst []byte, text string) []byte

AppendText XML-escapes cell text and applies OOXML's _xHHHH_ escape to characters XML cannot carry (C0 controls other than tab/newline and U+FFFE/U+FFFF) and to carriage returns, which XML parsers would normalize. Every literal "_x" prefix is protected, including incomplete sequences: expanding a later character inserts an underscore and could otherwise finish a new escape, for example "_x0000\r" becoming "_x0000_x000D_".

func DecodeText

func DecodeText(text string) string

DecodeText reverses the single-pass OOXML _xHHHH_ escape of stored text. Escaped underscores do not recursively decode a later literal sequence.

func DisplayNumber

func DisplayNumber(text string) (string, bool)

DisplayNumber returns the text of a stored double that a spreadsheet shows without rounding: at most ExactDigits significant digits, written without an exponent. ok is false when rounding to ExactDigits would change the stored value, for example a 16-digit identifier or 0.30000000000000004, so an importer reports it instead of silently using a different number.

func ExactNumber

func ExactNumber(text string) (string, bool)

ExactNumber returns the shortest exponent-free text that parses back to the stored double, for floating-point columns that receive the value itself.

func ParseReference

func ParseReference(reference string) (column, row int, ok bool)

ParseReference returns the 1-based column and row of a reference such as "B3". ok is false for malformed references or references outside a sheet.

func Serial

func Serial(wall time.Time) (string, bool)

Serial returns the serial number of a wall-clock time (its location is ignored). ok is false outside 1900-03-01 through 9999-12-31.

func Time

func Time(serial float64) (time.Time, bool)

Time converts a serial number to UTC wall-clock time, rounded to the millisecond resolution spreadsheets store. ok is false outside the range Serial produces.

Types

type Kind

type Kind uint8

Kind classifies a scalar wire type for spreadsheet storage. Text is always safe; typed kinds become numbers, booleans or dates when exactly representable.

const (
	Text Kind = iota
	Integer
	Number
	Decimal
	Boolean
	Date
	DateTime
	LocalDateTime
)

func KindOf

func KindOf(typ contract.Type) Kind

KindOf derives the storage kind of one scalar contract type. Enumerations and every other string format remain text.

Jump to

Keyboard shortcuts

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