gooxml

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2017 License: AGPL-3.0 Imports: 6 Imported by: 0

README

gooxml is a library for creation of OpenOffice documents (.docx, .xlsx and .pptx).

Build Status Go Report Card GoDoc

Status

The current focus is on documents (.docx). Some other code exists for spreadsheets and presentations, but it is even less complete. The current plan is to get documents working well, then spreadsheets, and finally presentations.

Installation

go get baliance.com/gooxml/
go build -i baliance.com/gooxml/...

Document Examples

Raw Types

The OOXML specification is large and creating a friendly API to cover the entire specification is a very time consuming endeavor. This library attempts to provide an easy to use API for common use cases in creating OOXML documents while allowing users to fall back to raw document manipulation should the library's API not cover a specific use case.

The raw XML based types reside in the schema/ directory. These types are accessible from the wrapper types via a X() method that returns the raw type.

For example, the library currently doesn't have an API for setting a document background color. However it's easy to do manually via editing the CT_Background element of the document.

dox := document.New()
doc.X().Background = wordprocessingml.NewCT_Background()
doc.X().Background.ColorAttr = &wordprocessingml.ST_HexColor{}
doc.X().Background.ColorAttr.ST_HexColorRGB = color.RGB(50, 50, 50).AsRGBString()

Contribution guidelines

CLA assistant

All contributors are must sign a contributor license agreement before their code will be reviewed and merged.

Licensing

This library is offered under a dual license. It is freely available for use under the terms of AGPLv3. If you would like to use this library for a closed source project, please contact sales@baliance.com.

There are no differences in functionality between the open source and commercial versions. You are encouraged to use the open source version to evaluate the library before purchasing a commercial license.

Consulting

Baliance also offers consulting services related to enhancing the gooxml library on a case by case basis. Please contact consulting@baliance.com if interested.

Documentation

Overview

Package gooxml provides creation, reading, and writing of ECMA 376 Open Office XML documents, spreadsheets and presentations. It is still early in development, but is progressing quickly. This library takes a slightly different approach from others, in that it starts by trying to support all of the ECMA-376 standard when marshaling/unmarshaling XML documents. From there it adds wrappers around the ECMA-376 derived types that provide a more convenient interface.

The raw XML based types reside in the ```schema/``` directory. These types are always accessible from the wrapper types via a ```X()``` method that returns the raw type. Except for the base documents (document.Document, spreadsheet.Workbook and presentation.Presentation), the other wrapper types are value types with non-pointer methods. They exist solely to modify and return data from one or more XML types.

The packages of interest are baliance.com/gooxml/document, baliance/gooxml/spreadsheet and baliance.com/gooxml/presentation.

Example (Document)
package main

import (
	"baliance.com/gooxml/document"
)

func main() {
	// see the baliance.com/gooxml/document documentation or _examples/document
	// for more examples
	doc := document.New()
	doc.AddParagraph().AddRun().AddText("Hello World!")
	doc.SaveToFile("document.docx")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPreserveSpaceAttr

func AddPreserveSpaceAttr(se *xml.StartElement, s string)

AddPreserveSpaceAttr adds an xml:space="preserve" attribute to a start element if it is required for the string s.

func Bool

func Bool(v bool) *bool

Bool returns a copy of v as a pointer.

func Float64

func Float64(v float64) *float64

Float64 returns a copy of v as a pointer.

func Int32

func Int32(v int32) *int32

Int32 returns a copy of v as a pointer.

func Int64

func Int64(v int64) *int64

Int64 returns a copy of v as a pointer.

func NeedsSpacePreserve

func NeedsSpacePreserve(s string) bool

NeedsSpacePreserve returns true if the string has leading or trailing space.

func RegisterConstructor

func RegisterConstructor(ns, name string, fn interface{})

RegisterConstructor registers a constructor function used for unmarshaling xsd:any elements.

func String

func String(v string) *string

String returns a copy of v as a pointer.

func Uint32

func Uint32(v uint32) *uint32

Uint32 returns a copy of v as a pointer.

func Uint64

func Uint64(v uint64) *uint64

Uint64 returns a copy of v as a pointer.

Types

type Any

type Any interface {
	MarshalXML(e *xml.Encoder, start xml.StartElement) error
	UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
}

Any is the interface used for marshaling/unmarshaling xsd:any

func CreateElement

func CreateElement(start xml.StartElement) (Any, error)

CreateElement creates an element with the given namespace and name. It is used to unmarshal some xsd:any elements to the appropriate concrete type.

type XSDAny

type XSDAny struct {
	XMLName xml.Name
	Attrs   []xml.Attr
	Data    []byte
	Nodes   []*XSDAny
}

XSDAny is used to marshal/unmarshal xsd:any types in the OOXML schema.

func (*XSDAny) MarshalXML

func (x *XSDAny) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface.

func (*XSDAny) UnmarshalXML

func (x *XSDAny) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface.

Directories

Path Synopsis
_examples
cmd
Package document provides creation, reading, and writing of ECMA 376 Open Office XML documents.
Package document provides creation, reading, and writing of ECMA 376 Open Office XML documents.
schema

Jump to

Keyboard shortcuts

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