importer

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func NeedSheet added in v0.11.0

func NeedSheet(sheetName string, wantSheetNames []string) bool

func ParseSheetSpecifier added in v0.11.0

func ParseSheetSpecifier(specifier string) (bookNameGlob string, specifiedSheetName string)

ParseSheetSpecifier parses the sheet specifier pattern like: "<BookNameGlob>[#SheetName]".

  1. The delimiter between BookNameGlob and SheetName is "#".
  2. The "SheetName" is optional, default is same as sheet name in the primary workbook.

func ResolveSheetSpecifier added in v0.11.0

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

ResolveSheetSpecifier resolve and return all related workbook paths.

  1. support Glob pattern, refer https://pkg.go.dev/path/filepath#Glob
  2. exclude self
  3. special process for CSV filename pattern: "<BookName>#<SheetName>.csv"

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, mode ImporterMode, cloned bool) (*CSVImporter, error)

type ExcelImporter

type ExcelImporter struct {
	*book.Book
}

func NewExcelImporter

func NewExcelImporter(filename string, sheetNames []string, parser book.SheetParser, mode ImporterMode, cloned bool) (*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
	// 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 New

func New(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.
}

func GetMergerImporters added in v0.10.6

func GetMergerImporters(inputDir, primaryBookName, sheetName string, sheetSpecifiers []string, subdirRewrites map[string]string) ([]ImporterInfo, error)

GetMergerImporters return all related importer infos.

  1. support Glob pattern, refer https://pkg.go.dev/path/filepath#Glob
  2. exclude self
  3. special process for CSV filename pattern: "<BookName>#<SheetName>.csv"

func GetScatterImporters added in v0.10.7

func GetScatterImporters(inputDir, primaryBookName, sheetName string, scatterSpecifiers []string, subdirRewrites map[string]string) ([]ImporterInfo, error)

GetScatterImporters return all related importer infos.

  1. support Glob pattern, refer https://pkg.go.dev/path/filepath#Glob
  2. exclude self
  3. special process for CSV filename pattern: "<BookName>#<SheetName>.csv"

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

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

type Options

type Options struct {
	Sheets          []string         // sheet names 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(filename string, sheets []string, parser book.SheetParser, mode ImporterMode, cloned bool) (*XMLImporter, error)

type YAMLImporter added in v0.11.0

type YAMLImporter struct {
	*book.Book
}

func NewYAMLImporter added in v0.11.0

func NewYAMLImporter(filename string, sheetNames []string, parser book.SheetParser, mode ImporterMode, cloned bool) (*YAMLImporter, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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