openoffice

package module
v0.0.0-...-064f5dd Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 9 Imported by: 1

README

go-openoffice

A Go library for reading OpenOffice/LibreOffice .ods (and .odf) files.

Example

$ cat ./examples/dump/main.go
package main

import "fmt"
import "strings"
import "github.com/multiprocessio/go-openoffice"

func main() {
	f, err := openoffice.OpenODS("testdata/test.ods")
	if err != nil {
		panic(err)
	}

	doc, err := f.ParseContent()
	if err != nil {
		panic(err)
	}

	for _, t := range doc.Sheets {
		fmt.Printf("Sheet Name: %s, Rows: %d\n", t.Name, len(t.Rows))

		for _, row := range t.Strings() {
			fmt.Println(strings.Join(row, ","))
		}

		fmt.Println()
	}
}

Users

This library is used by:

History

This project is a fork of https://github.com/knieriem/odf.

Documentation

Overview

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

Index

Constants

View Source
const (
	ISO8601 = "2006-01-02T15:04:05"
)
View Source
const (
	MimeTypePfx = "application/vnd.oasis.opendocument."
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DocStats

type DocStats struct {
	Tables     int `xml:"table-count,attr"`
	Cells      int `xml:"cell-count,attr"`
	Images     int `xml:"image-count,attr"`
	Objects    int `xml:"object-count,attr"`
	Pages      int `xml:"page-count,attr"`
	Paragraphs int `xml:"paragraph-count,attr"`
	Words      int `xml:"word-count,attr"`
	Characters int `xml:"character-count,attr"`
}

type DocumentMeta

type DocumentMeta struct {
	XMLName xml.Name `xml:"urn:oasis:names:tc:opendocument:xmlns:office:1.0 document-meta"`

	Version string `xml:"office version,attr"`
	Meta    Meta   `xml:"meta"`
}

type Meta

type Meta struct {
	Title string `xml:"title"`

	InitialCreator Time `xml:"initial-creator"`
	CreationDate   Time `xml:"creation-date"`

	DcCreator string `xml:"dc creator"`
	DcDate    string `xml:"dc date"`
	DcLang    string `xml:"dc language"`

	EditingCycles   int    `xml:"editing-cycles"`
	EditingDuration string `xml:"editing-duration"`

	Stats DocStats `xml:"document-statistic"`

	Generator string `xml:"generator"`

	UserDefined []struct {
		Name string `xml:"name,attr"`
		Text string `xml:",chardata"`
	} `xml:"user-defined"`
}

type ODFFile

type ODFFile struct {
	*zip.Reader

	MimeType string
	// contains filtered or unexported fields
}

func NewODFReader

func NewODFReader(r io.ReaderAt, size int64) (*ODFFile, error)

NewReader initializes a File struct with an already opened ODF file, and checks the file's MIME type. The returned *ODFFile provides access to files embedded in the ODF file, like content.xml.

func OpenODF

func OpenODF(odfName string) (*ODFFile, error)

Open an OpenDocument file for reading, and check its MIME type. The returned *ODFFile provides -- via its Open method -- access to files embedded in the ODF, like content.xml.

func (*ODFFile) Close

func (f *ODFFile) Close() error

func (*ODFFile) Meta

func (f *ODFFile) Meta() (docMeta *DocumentMeta, err error)

func (*ODFFile) Open

func (f *ODFFile) Open(name string) (io.ReadCloser, error)

type ODSCell

type ODSCell 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 []ODSPar `xml:"p"`
}

func (*ODSCell) IsEmpty

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

func (*ODSCell) PlainText

func (c *ODSCell) 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 ODSDoc

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

type ODSFile

type ODSFile struct {
	*ODFFile
}

func NewODSReader

func NewODSReader(r io.ReaderAt, size int64) (*ODSFile, error)

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

func OpenODS

func OpenODS(fileName string) (*ODSFile, error)

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

func (*ODSFile) ParseContent

func (f *ODSFile) ParseContent() (*ODSDoc, 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 ODSPar

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

func (*ODSPar) PlainText

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

type ODSRow

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

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

func (*ODSRow) IsEmpty

func (r *ODSRow) IsEmpty() bool

func (*ODSRow) Strings

func (r *ODSRow) 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 ODSSheet

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

func (*ODSSheet) Height

func (t *ODSSheet) Height() int

func (*ODSSheet) Strings

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

func (*ODSSheet) Width

func (t *ODSSheet) Width() int

type Time

type Time string

func (Time) Time

func (s Time) Time() (t time.Time, err error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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