Documentation
¶
Overview ¶
Package fileio moves data between sheets and other file formats: CSV and TSV, Excel workbooks, SQLite databases, Parquet files and Lotus 1-2-3 worksheets. Everything is pure Go. The sheet package knows none of these formats: importers build a sheet through its public API (Load, LoadColWidth, RecalcAll) and exporters read a Snapshot of one. Each format is a row of the table in formats.go and a file of its own.
Index ¶
- Variables
- func CellValue(c SnapCell) nuon.Value
- func HTMLChart(c SnapChart) string
- func HTMLDocument(title, body, extra string) string
- func HTMLGrid(snap *Snapshot) (string, string)
- func HTMLPanel(title, name, where string) string
- func HTMLStyle() string
- func NUONCell(v nuon.Value) sheet.LiveCell
- func TableName(s string) string
- func WriteHTML(w io.Writer, p HTMLPage) (note string, err error)
- type Dialect
- type ErrNeedTable
- type ExportOptions
- type ExportResult
- type HTMLPage
- type Kind
- func (k Kind) About() string
- func (k Kind) CanExport() bool
- func (k Kind) CanImport() bool
- func (k Kind) Ext() string
- func (k Kind) Grows() bool
- func (k Kind) HasTables() bool
- func (k Kind) HoldsSheets() bool
- func (k Kind) IsText() bool
- func (k Kind) Label() string
- func (k Kind) MenuTitle() string
- func (k Kind) Noun() string
- func (k Kind) String() string
- type LineFormat
- type Options
- type Progress
- type Result
- type SnapCell
- type SnapChart
- type SnapName
- type Snapshot
- type TableInfo
- type Tail
- type TailRows
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = errors.New("not a format 012 can import")
ErrUnsupported is returned for a file whose extension isn't known.
Functions ¶
func CellValue ¶ added in v0.3.0
CellValue is a cell as a NUON value, typed by its format as a table written as NUON or JSON types it: what 012 get writes for one cell.
func HTMLDocument ¶ added in v0.4.0
HTMLDocument is a whole page: title, style sheet, body and script, with extra added to the script (the MCP view's messages).
func HTMLGrid ¶ added in v0.4.0
HTMLGrid draws the snapshot as 012's grid: column letters and row numbers, the cells as they show with their styles, borders and the looks of rules, and the charts over them. It returns the fragment and a note when rows were left out.
func HTMLPanel ¶ added in v0.4.0
HTMLPanel is the control panel's three lines: the title with the mode indicator, the name box (holding name until a cell is pointed at) and formula bar, and the context line saying what the page shows.
func HTMLStyle ¶ added in v0.4.0
func HTMLStyle() string
HTMLStyle is the style sheet of 012's HTML pages, for a page built around HTMLGrid or HTMLChart; the root element takes the class dark or light to choose a palette over the reader's preference.
func NUONCell ¶ added in v0.3.0
NUONCell is the cell a NUON value makes: its value, text as the value's own, and its format (a file size's Size, a date's Date time, in the local time zone), as importing it would store it.
Types ¶
type ErrNeedTable ¶
type ErrNeedTable struct{ Tables []TableInfo }
ErrNeedTable is returned for a SQLite database with several tables when Options names neither a table nor a query; Tables lists them.
func (*ErrNeedTable) Error ¶
func (e *ErrNeedTable) Error() string
type ExportOptions ¶
type ExportOptions struct {
Table string // SQLite: the table to write; replaced if it exists
}
ExportOptions tune an export.
type ExportResult ¶
ExportResult says what an export wrote and what it couldn't keep.
func Encode ¶ added in v0.3.0
Encode writes a snapshot to w in the text format k (see Kind.IsText): what 012 --pipe writes to standard output.
func Export ¶
func Export(ctx context.Context, name string, k Kind, snap *Snapshot, opt ExportOptions) (*ExportResult, error)
Export writes a snapshot of a sheet to name in format k.
type HTMLPage ¶ added in v0.4.0
type HTMLPage struct {
Title string // the page's title, and the first line's
Snap *Snapshot // the cells, when Chart is nil
Chart *SnapChart
}
HTMLPage is what an HTML page shows: a sheet or range, or one chart.
type Kind ¶
type Kind int
Kind is an external file format.
func ExportKindOf ¶ added in v0.4.0
ExportKindOf recognizes a file's format by its extension, including formats 012 only writes (HTML).
func (Kind) About ¶
About says what downloading in this format writes; empty for formats that can't be exported.
func (Kind) Grows ¶ added in v0.3.0
Grows reports whether a file of kind k can be followed as it grows, its new rows read without reading it again: text tables, which Tail reads.
func (Kind) HasTables ¶
HasTables reports whether a file of this kind is a database of tables: importing picks one (see Tables), and a download writes the sheet or the selection as a named table (ExportOptions.Table).
func (Kind) HoldsSheets ¶
HoldsSheets reports whether a file of this kind holds several named sheets, so a download writes the whole workbook (see SnapBook).
func (Kind) IsText ¶ added in v0.3.0
IsText reports whether this kind is text Encode writes to a stream: CSV, TSV, JSON or NUON.
func (Kind) MenuTitle ¶
MenuTitle is the format's entry in the Download menu, e.g. "Microsoft Excel (.xlsx)"; empty for formats that can't be exported.
type LineFormat ¶
LineFormat is the format and style of a whole column or row.
type Options ¶
type Options struct {
// Table is the SQLite table to import, or Query a SELECT to run.
// With neither, a database with one table imports it.
Table, Query string
Progress *Progress
// MaxCells is the most cells to keep, whole rows at a time; 0 is the
// max-cells setting (sheet.MaxCells). WK1 files keep their own limits.
MaxCells int
// Locale is what CSV and TSV fields are read in (see numberLocale);
// nil is en-US.
Locale *locale.Locale
}
Options tune an import.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress reports how far an import has got. The importer updates it from its goroutine; the UI reads it on a timer.
func NewProgress ¶
func NewProgress() *Progress
NewProgress returns a progress with an unknown total.
type Result ¶
type Result struct {
Sheet *sheet.Sheet
Kind Kind
Rows int // rows of the file that were read, including a header
Notes []string
}
Result is an imported sheet and what the import had to leave out or change, in sentences for the context line.
func Import ¶
Import reads the file name into a new sheet. It checks ctx between rows, so a long import can be cancelled.
func ImportReader ¶ added in v0.3.0
ImportReader reads a table from r into a new sheet named name (as a file's sheet is named after the file), telling its format from the text; Result.Kind is NUON, JSON, CSV or TSV. It checks ctx between rows and updates opt.Progress.
type SnapCell ¶
type SnapCell struct {
Input string
Value sheet.Value
Format sheet.Format // as displayed, including one inferred from a formula
Own sheet.Format // the cell's own format
Style sheet.Style
Formula bool
Sheets []string // the sheets a formula names, as written
Tables []string // the tables a formula reads, as written
}
SnapCell is one non-blank cell of a snapshot.
type SnapChart ¶ added in v0.4.0
SnapChart is a chart with the values it draws, read when the snapshot is taken.
type Snapshot ¶
type Snapshot struct {
// Range is what's exported. Whole-sheet exports start at A1, as
// Sheets' downloads do, so cells keep their addresses.
Range sheet.Rect
Cells map[sheet.Addr]SnapCell
Widths map[int]int // non-default column widths
Name string // what to call the data: a sheet or table name
// Locale is the sheet's, which text formats (CSV) are written in.
Locale *locale.Locale
// ColFormats and RowFormats are the formats of whole columns and
// rows, for formats that keep them (XLSX).
ColFormats, RowFormats map[int]LineFormat
// Sheets are every sheet of the workbook, in order, for formats that
// hold several (XLSX); the snapshot itself is one of them, the one
// shown. Nil exports just this snapshot. Names are the workbook's
// named ranges.
Sheets []*Snapshot
Names []SnapName
Hidden bool // a hidden sheet of Sheets, written hidden
// FrozenRows and FrozenCols are the frozen panes; Filter is the
// sheet's filter, if any, and HiddenRows the rows of Range it hides,
// for formats that keep them (XLSX).
FrozenRows, FrozenCols int
Filter *sheet.Filter
HiddenRows map[int]bool
// Spills are the cells each formula whose array spills covers, by
// the formula's cell, for formats that keep formulas (XLSX).
Spills map[sheet.Addr]sheet.Rect
// CondFormats and Validations are the sheet's rules, for formats
// that keep them (XLSX).
CondFormats []sheet.CondFormat
Validations []sheet.Validation
// Notes are the cells' notes in the range, for formats that keep
// them (XLSX, as comments). A note may be on a cell with no contents.
Notes map[sheet.Addr]string
// Heights are the rows' heights set by hand, in lines, and Merges
// the merged cells in the range, for formats that keep them (XLSX).
Heights map[int]int
Merges []sheet.Rect
// Tables are the tables wholly in the range, for formats that keep
// them (XLSX).
Tables []sheet.Table
// Looks are how the sheet's rules draw the range's cells, and Charts
// the charts whose top-left cell is in it, for formats that show
// what the screen shows (HTML); see snapdrawn.go.
Looks map[sheet.Addr]sheet.Look
Charts []SnapChart
}
Snapshot is a copy of the part of a sheet being exported, taken on the UI goroutine so the file can be written in the background while the sheet keeps changing.
type Tail ¶ added in v0.3.0
type Tail struct {
// contains filtered or unexported fields
}
A Tail reads a table of kind k from text that arrives in pieces.
type TailRows ¶ added in v0.3.0
type TailRows struct {
// Header is the table's first row when it's new or changed: a CSV
// file's first record, or NUON's column names as they're seen.
Header sheet.LiveRow
Rows []sheet.LiveRow
}
TailRows are the rows a piece of text completed.
func NUONRows ¶ added in v0.3.0
NUONRows reads NUON, a notebook cell's output, as a region's rows: a table's header and rows, a record as one row, a list of values that aren't records as one column named value, and any other value as that column with one row. It keeps at most maxCells cells, whole rows (0 for the max-cells setting), and says what it left out.
Source Files
¶
- builder.go
- csv.go
- csvlocale.go
- fileio.go
- formats.go
- formula.go
- html.go
- htmlcell.go
- htmlgrid.go
- htmlstyle.go
- numfmt.go
- nuon.go
- nuonrows.go
- nuonwrite.go
- parquet.go
- snapdrawn.go
- snapshot.go
- sqlite.go
- stream.go
- tail.go
- wk1.go
- wk1formula.go
- xlsx.go
- xlsxarray.go
- xlsxbook.go
- xlsximport.go
- xlsxlayout.go
- xlsxlines.go
- xlsxnotes.go
- xlsxpkg.go
- xlsxrules.go
- xlsxrulesimport.go
- xlsxrulesmore.go
- xlsxrulesread.go
- xlsxsheet.go
- xlsxshift.go
- xlsxstyles.go
- xlsxtables.go
- xlsxview.go
- xlsxviewread.go
- xlsxwrite.go