Documentation
¶
Overview ¶
Package csvx provides a specification-first reader and writer for CSVX workbooks.
Index ¶
- func Convert(input, output string) error
- func ExtractPackage(filename, directory string) error
- func PackageDirectory(directory, output string) error
- func WritePackage(workbook *Workbook, output string) error
- type Calculation
- type CellMetadata
- type Column
- type Diagnostic
- type Manifest
- type Sheet
- type SheetEntry
- type SourceMetadata
- type Style
- type ValidationResult
- type Value
- type Workbook
- type WorkbookDocument
- type XLSXDiagnostic
- type XLSXFeatureCounts
- type XLSXInspection
- type XLSXSheet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractPackage ¶
ExtractPackage extracts a CSVX ZIP package into an unpacked directory.
func PackageDirectory ¶
PackageDirectory writes an unpacked CSVX package directory as a ZIP .csvx file.
func WritePackage ¶
WritePackage writes a workbook to a deterministic CSVX ZIP package.
Types ¶
type Calculation ¶
type Calculation struct {
Mode string `json:"mode,omitempty"`
Iteration bool `json:"iteration,omitempty"`
}
Calculation contains workbook calculation settings.
type CellMetadata ¶
type CellMetadata struct {
Type string `json:"type,omitempty"`
Formula string `json:"formula,omitempty"`
Cached *Value `json:"cached,omitempty"`
Style string `json:"style,omitempty"`
Validation json.RawMessage `json:"validation,omitempty"`
}
CellMetadata contains behavior that cannot be represented in CSV.
type Column ¶
type Column struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type,omitempty"`
Width float64 `json:"width,omitempty"`
}
Column describes a CSV column and its optional CSVX type.
type Diagnostic ¶
type Diagnostic struct {
Code string `json:"code"`
Path string `json:"path,omitempty"`
Message string `json:"message"`
Severity string `json:"severity"`
}
Diagnostic describes a validation error or warning at a package resource.
type Manifest ¶
type Manifest struct {
Format string `json:"format"`
Version string `json:"version"`
Workbook string `json:"workbook"`
Files []string `json:"files"`
}
Manifest identifies a CSVX package and its resources.
type Sheet ¶
type Sheet struct {
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
MetadataPath string `json:"metadata,omitempty"`
Columns []Column `json:"columns"`
Records [][]string `json:"records"`
RowHeights map[int]float64 `json:"rowHeights,omitempty"`
Cells map[string]CellMetadata `json:"cells,omitempty"`
Extra map[string]json.RawMessage `json:"-"`
}
Sheet is a CSV-backed worksheet. Records excludes the CSV header row.
type SheetEntry ¶
type SheetEntry struct {
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Metadata string `json:"metadata,omitempty"`
}
SheetEntry locates a sheet's CSV and optional metadata sidecar in a package.
type SourceMetadata ¶
type SourceMetadata struct {
Format string `json:"format"`
Filename string `json:"filename"`
SHA256 string `json:"sha256"`
Authority string `json:"authority"`
ImportedAt string `json:"importedAt"`
Importer string `json:"importer"`
Features XLSXFeatureCounts `json:"features,omitempty"`
Warnings []XLSXDiagnostic `json:"warnings,omitempty"`
}
SourceMetadata describes an embedded external workbook preserved for interoperability.
type Style ¶
type Style schema.CSVXStylesStylesElem
Style is a single style record. Its field shape is generated from csvx-spec's styles.schema.json (see internal/schema/generated.go) rather than hand-typed, so it cannot silently drift from the schema the way the previous hand-written map[string]map[string]any representation did.
This is a defined type over the generated struct, not a plain alias, solely so MarshalJSON below can omit the generated AdditionalProperties bucket field until this engine implements real additionalProperties round-tripping on both read and write (styles.json is not read back in anywhere yet, so nothing currently depends on inheriting the generated UnmarshalJSON here).
func (Style) MarshalJSON ¶
MarshalJSON serializes a Style without the generated AdditionalProperties bucket field, which encoding/json would otherwise emit as a literal `"AdditionalProperties": null` key — schema- legal (styles.schema.json allows additional properties) but wrong output.
type ValidationResult ¶
type ValidationResult struct {
Valid bool `json:"valid"`
Errors []Diagnostic `json:"errors"`
Warnings []Diagnostic `json:"warnings"`
}
ValidationResult contains machine-readable package validation output.
func Validate ¶
func Validate(filename string) ValidationResult
Validate checks a CSVX ZIP file or unpacked CSVX directory.
type Value ¶
type Value struct {
Type string `json:"type"`
Value any `json:"value,omitempty"`
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
Value is a typed CSVX value used by formulas, caches, and diagnostics.
type Workbook ¶
type Workbook struct {
ID string `json:"id"`
Version string `json:"version"`
Sheets []*Sheet `json:"sheets"`
Calculation Calculation `json:"calculation,omitempty"`
Source *SourceMetadata `json:"source,omitempty"`
Styles []Style `json:"styles,omitempty"`
SourceBytes []byte `json:"-"`
}
Workbook is the canonical in-memory representation of a CSVX workbook.
func OpenDirectory ¶
OpenDirectory reads an unpacked CSVX package directory.
type WorkbookDocument ¶
type WorkbookDocument struct {
ID string `json:"id"`
Version string `json:"version"`
Sheets []SheetEntry `json:"sheets"`
Calculation Calculation `json:"calculation,omitempty"`
Source *SourceMetadata `json:"source,omitempty"`
Styles string `json:"styles,omitempty"`
}
WorkbookDocument is the serialized workbook resource.
type XLSXDiagnostic ¶
type XLSXDiagnostic struct {
Severity string `json:"severity"`
Feature string `json:"feature"`
Path string `json:"path,omitempty"`
Message string `json:"message"`
}
XLSXDiagnostic records an interoperability limitation or observation.
type XLSXFeatureCounts ¶
type XLSXFeatureCounts struct {
Styles int `json:"styles"`
NumberFormats int `json:"numberFormats"`
Drawings int `json:"drawings"`
Charts int `json:"charts"`
Images int `json:"images"`
Comments int `json:"comments"`
Persons int `json:"persons"`
Macros int `json:"macros"`
Relationships int `json:"relationships"`
}
XLSXFeatureCounts summarizes workbook features relevant to CSVX interoperability.
type XLSXInspection ¶
type XLSXInspection struct {
Format string `json:"format"`
Filename string `json:"filename"`
SHA256 string `json:"sha256"`
Sheets []XLSXSheet `json:"sheets"`
Features XLSXFeatureCounts `json:"features"`
Resources []string `json:"resources"`
Warnings []XLSXDiagnostic `json:"warnings"`
}
XLSXInspection describes the portable features and package resources detected in an XLSX file.
func InspectXLSX ¶
func InspectXLSX(filename string) (*XLSXInspection, error)
InspectXLSX reads an XLSX package without executing macros, links, or external resources.