unioffice: github.com/unidoc/unioffice/spreadsheet/format Index | Files

package format

import "github.com/unidoc/unioffice/spreadsheet/format"

Package format provides support for parsing and evaluating spreadsheetml/Excel number formats.

Internally spreadsheets store numbers and dates values as a text representation of a floating point number (e.g. 1.2345). This number is then displayed in Excel or another spreadsheet viewer differently depending on the number fornat of the cell style applied to the cell.

As an example, the same value of 1.2345 can be displayed as: - "1" with format "0" - "1.2" with format "0.0" - "1.23" with format "0.00" - "1.235" with format "0.000" - "123%" with format "0%" - "1 23/100" with fornat "0 0/100" - "1.23E+00" with format "0.00E+00" - "29:37:41s" with format `[h]:mm:ss"s"`

Index

Package Files

doc.go fmttype_string.go format.go isnumber.go lex.go lexer.go time.go

func IsNumber Uses

func IsNumber(data string) (isNumber bool)

func Number Uses

func Number(v float64, f string) string

Number is used to format a number with a format string. If the format string is empty, then General number formatting is used which attempts to mimic Excel's general formatting.

func NumberGeneric Uses

func NumberGeneric(v float64) string

NumberGeneric formats the number with the generic format which attemps to mimic Excel's general formatting.

func String Uses

func String(v string, f string) string

String returns the string formatted according to the type. In format strings this is the fourth item, where '@' is used as a placeholder for text.

func Value Uses

func Value(v string, f string) string

Value formats a value as a number or string depending on if it appears to be a number or string.

type FmtType Uses

type FmtType byte

FmtType is the type of a format token. go:generate stringer -type=FmtType

const (
    FmtTypeLiteral FmtType = iota
    FmtTypeDigit
    FmtTypeDigitOpt
    FmtTypeComma
    FmtTypeDecimal
    FmtTypePercent
    FmtTypeDollar
    FmtTypeDigitOptThousands
    FmtTypeUnderscore
    FmtTypeDate
    FmtTypeTime
    FmtTypeFraction
    FmtTypeText
)

Format type constants.

func (FmtType) String Uses

func (i FmtType) String() string

type Format Uses

type Format struct {
    Whole         []Token
    Fractional    []Token
    Exponent      []Token
    IsExponential bool
    // contains filtered or unexported fields
}

Format is a parsed number format.

func Parse Uses

func Parse(s string) []Format

func (*Format) AddToken Uses

func (f *Format) AddToken(t FmtType, l []byte)

AddToken adds a format token to the format.

type Lexer Uses

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

func (*Lexer) Lex Uses

func (l *Lexer) Lex(r io.Reader)

type Token Uses

type Token struct {
    Type     FmtType
    Literal  byte
    DateTime string
}

Token is a format token in the Excel format string.

Package format imports 8 packages (graph) and is imported by 4 packages. Updated 2019-05-23. Refresh now. Tools for package owners.