importer

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BOM = []byte{0xEF, 0xBB, 0xBF}

BOM stands for byte-order mark. Refer: https://en.wikipedia.org/wiki/Byte_order_mark.

View Source
var ErrSheetNotFound = errors.New("sheet not found")

Functions

func ResolveSheetSpecifier added in v0.11.0

func ResolveSheetSpecifier(inputDir, primaryBookName string, sheetSpecifier string, subdirRewrites map[string]string) (relBookPaths map[string]bool, sheetNamePattern string, err error)

ResolveSheetSpecifier resolves and returns all related workbook paths and sheet names.

  1. support filepath.Glob pattern for workbook file, see https://pkg.go.dev/path/filepath#Glob
  2. special process for CSV filename pattern: "<BookNamePattern>#<SheetNamePattern>.csv"

Types

type CSVImporter

type CSVImporter struct {
	*book.Book
}

CSVImporter recognizes pattern: "<BookName>#<SheetName>.csv"

func NewCSVImporter

func NewCSVImporter(ctx context.Context, filename string, setters ...Option) (*CSVImporter, error)

type Cache added in v0.17.0

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

Cache reuses imported data while it remains reachable. Sources own decoded sheets and workbook handles; entries are immutable importer views for one option set. Load may be called concurrently. The cache has no shutdown step.

func NewCache added in v0.17.0

func NewCache() *Cache

NewCache creates an empty importer cache.

func (*Cache) EnableProfiling added in v0.17.0

func (c *Cache) EnableProfiling()

EnableProfiling enables pprof labels and cache metrics. Call it before the cache is used.

func (*Cache) Load added in v0.17.0

func (c *Cache) Load(ctx context.Context, filename string, setters ...Option) (Importer, error)

Load returns a cached importer or loads it once for concurrent callers.

func (*Cache) LoadMergerImporters added in v0.17.0

func (c *Cache) LoadMergerImporters(ctx context.Context, inputDir, primaryBookName, primarySheetName string, sheetSpecifiers []string, subdirRewrites map[string]string) ([]ImporterInfo, error)

LoadMergerImporters returns related merger importers through the cache. A nil cache performs direct loads.

func (*Cache) LoadScatterImporters added in v0.17.0

func (c *Cache) LoadScatterImporters(ctx context.Context, inputDir, primaryBookName, primarySheetName string, sheetSpecifiers []string, subdirRewrites map[string]string) ([]ImporterInfo, error)

LoadScatterImporters returns related scatter importers through the cache. A nil cache performs direct loads.

func (*Cache) Metrics added in v0.17.0

func (c *Cache) Metrics() (requests, imports, sheets, paths int64)

Metrics returns load requests, importer loads, decoded sheets, and paths. Counters remain zero unless profiling was enabled before loading.

type ExcelImporter

type ExcelImporter struct {
	*book.Book
}

func NewExcelImporter

func NewExcelImporter(ctx context.Context, filename string, setters ...Option) (*ExcelImporter, error)

type Importer

type Importer interface {
	// Filename returns the parsed filename of the original inputed filename.
	// 	- Excel: same as the inputed filename.
	// 	- CSV: recognizes pattern: "<BookName>#<SheetName>.csv", and returns Glob name "<BookName>#*.csv".
	// 	- XML: same as the inputed filename.
	Filename() string
	// Bookname returns the book name after parsing the original inputed filename.
	// 	- Excel: the base filename without file extension.
	// 	- CSV: recognizes pattern: "<BookName>#<SheetName>.csv", and returns "<BookName>".
	// 	- XML: the base filename without file extension.
	BookName() string
	// Format returns workboot format.
	Format() format.Format
	// GetBookOptions creates a new tableaupb.WorkbookOptions
	// based on this special sheet(#)'s info.
	GetBookOptions() *tableaupb.WorkbookOptions
	// GetSheets returns all sheets in order of the book.
	GetSheets() []*book.Sheet
	// GetSheet returns a Sheet of the specified sheet name.
	GetSheet(name string) *book.Sheet
}

func New

func New(ctx context.Context, filename string, setters ...Option) (Importer, error)

New creates a new importer.

type ImporterInfo added in v0.11.0

type ImporterInfo struct {
	Importer
	SpecifiedSheetName string // Empty means no sheet specified.
}

type ImporterMode added in v0.10.6

type ImporterMode int
const (
	UnknownMode ImporterMode = 0
	Protogen    ImporterMode = 1
	Confgen     ImporterMode = 2
)

Importer mode

type Option

type Option func(*Options)

Option is the functional option type.

func Cloned added in v0.10.7

func Cloned(primaryBookName string) Option

Cloned specifies this book cloned (same schema different data) from the main book.

func Mode added in v0.10.6

func Mode(m ImporterMode) Option

Mode specifies importer mode.

func Parser

func Parser(parser book.SheetParser) Option

Parser specifies parser to parse the worksheet.

func Sheets

func Sheets(sheets []string) Option

Sheets specifies sheet name patterns (by filepath.Match) to import.

type Options

type Options struct {
	Sheets          []string         // sheet name patterns (by filepath.Match) to import
	Parser          book.SheetParser // parser to parse the worksheet
	Mode            ImporterMode     // importer mode
	Cloned          bool             // this book cloned (same schema different data) from the main book
	PrimaryBookName string           // if cloned, this is primary book name
}

type XMLImporter

type XMLImporter struct {
	*book.Book
}

func NewXMLImporter

func NewXMLImporter(ctx context.Context, filename string, setters ...Option) (*XMLImporter, error)

type YAMLImporter added in v0.11.0

type YAMLImporter struct {
	*book.Book
}

func NewYAMLImporter added in v0.11.0

func NewYAMLImporter(ctx context.Context, filename string, setters ...Option) (*YAMLImporter, error)

Directories

Path Synopsis
Package xlsx reads raw cell values from selected OOXML worksheets.
Package xlsx reads raw cell values from selected OOXML worksheets.

Jump to

Keyboard shortcuts

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