ods

package
v0.0.0-...-39865ca Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Unlicense Imports: 7 Imported by: 0

Documentation

Overview

This package implements rudimentary support for reading Open Document Spreadsheet files. At current stage table data can be accessed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	XMLName xml.Name

	// attributes
	ValueType    string `xml:"value-type,attr"`
	Value        string `xml:"value,attr"`
	Formula      string `xml:"formula,attr"`
	RepeatedCols int    `xml:"number-columns-repeated,attr"`
	ColSpan      int    `xml:"number-columns-spanned,attr"`

	P []Par `xml:"p"`
}

func (*Cell) IsEmpty

func (c *Cell) IsEmpty() (empty bool)

func (*Cell) PlainText

func (c *Cell) PlainText(b *bytes.Buffer) string

PlainText extracts the text from a cell. Space tags (<text:s text:c="#">) are recognized. Inline elements (like span) are ignored, but the text they contain is preserved

type Doc

type Doc struct {
	XMLName xml.Name `xml:"document-content"`
	Table   []Table  `xml:"body>spreadsheet>table"`
}

type File

type File struct {
	*odf.File
}

func NewReader

func NewReader(r io.ReaderAt, size int64) (*File, error)

NewReader initializes a File struct with an already opened ODS file, and checks the spreadsheet's media type.

func Open

func Open(fileName string) (*File, error)

Open an ODS file. If the file doesn't exist or doesn't look like a spreadsheet file, an error is returned.

func (*File) ParseContent

func (f *File) ParseContent(doc *Doc) (err error)

Parse the content.xml part of an ODS file. On Success the returned Doc will contain the data of the rows and cells of the table(s) contained in the ODS file.

type Par

type Par struct {
	XML string `xml:",innerxml"`
}

func (*Par) PlainText

func (p *Par) PlainText(b *bytes.Buffer) string

type Row

type Row struct {
	RepeatedRows int `xml:"number-rows-repeated,attr"`

	Cell []Cell `xml:",any"` // use ",any" to match table-cell and covered-table-cell
}

func (*Row) IsEmpty

func (r *Row) IsEmpty() bool

func (*Row) Strings

func (r *Row) Strings(b *bytes.Buffer) (row []string)

Return the contents of a row as a slice of strings. Cells that are covered by other cells will appear as empty strings.

type Table

type Table struct {
	Name   string   `xml:"name,attr"`
	Column []string `xml:"table-column"`
	Row    []Row    `xml:"table-row"`
}

func (*Table) Height

func (t *Table) Height() int

func (*Table) Strings

func (t *Table) Strings() (s [][]string)

func (*Table) Width

func (t *Table) Width() int

Jump to

Keyboard shortcuts

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