importer

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenCSVBookFilenamePattern added in v0.10.6

func GenCSVBookFilenamePattern(dir, bookName string) string

func ParseCSVFilenamePattern added in v0.9.7

func ParseCSVFilenamePattern(filename string) (bookName, sheetName string, err error)

Types

type CSVImporter

type CSVImporter struct {
	*book.Book
}

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

func NewCSVImporter

func NewCSVImporter(filename string, sheetNames []string, parser book.SheetParser) (*CSVImporter, error)

type ExcelImporter

type ExcelImporter struct {
	*book.Book
}

func NewExcelImporter

func NewExcelImporter(filename string, sheetNames []string, parser book.SheetParser, topN uint) (*ExcelImporter, error)

topN: 0 means read all rows

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
	// Metabook returns the metadata of the book.
	Metabook() *tableaupb.Metabook
	// 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 GetMergerImporters added in v0.10.6

func GetMergerImporters(primaryWorkbookPath, sheetName string, merger []string) ([]Importer, error)

GetMergerImporters gathers all merger importers.

  1. support Glob pattern, refer https://pkg.go.dev/path/filepath#Glob
  2. exclude self

func New

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

New creates a new importer.

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 Mode added in v0.10.6

func Mode(m ImporterMode) Option

func Parser

func Parser(parser book.SheetParser) Option

func Sheets

func Sheets(sheets []string) Option

func TopN added in v0.9.14

func TopN(n uint) Option

type Options

type Options struct {
	Sheets []string         // sheet names to import
	Parser book.SheetParser // parser to parse the worksheet
	TopN   uint             // read top N rows, 0 means read all rows
	Mode   ImporterMode     // importer mode
}

type XMLImporter

type XMLImporter struct {
	*book.Book
}

func NewXMLImporter

func NewXMLImporter(filename string, sheets []string, parser book.SheetParser, mode ImporterMode) (*XMLImporter, error)

TODO: options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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