unioffice: github.com/unidoc/unioffice Index | Examples | Files | Directories

package unioffice

import "github.com/unidoc/unioffice"

Package unioffice provides creation, reading, and writing of ECMA 376 Office Open 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 github.com/unidoc/unioffice/document, unidoc/unioffice/spreadsheet and github.com/unidoc/unioffice/presentation.

Code:

// see the github.com/unidoc/unioffice/document documentation or _examples/document
// for more examples
doc := document.New()
doc.AddParagraph().AddRun().AddText("Hello World!")
doc.SaveToFile("document.docx")

Code:

// see the github.com/unidoc/unioffice/spreadsheet documentation or _examples/spreadsheet
// for more examples
ss := spreadsheet.New()
sheet := ss.AddSheet()
sheet.AddRow().AddCell().SetString("Hello")
sheet.Cell("B1").SetString("World!")
ss.SaveToFile("workbook.xlsx")

Index

Examples

Package Files

creator.go doc.go filenames.go log.go mingo.go mingo_18.go optional.go schemas.go xml.go xsdany.go

Constants

const (
    ContentTypesFilename = "[Content_Types].xml"
    BaseRelsFilename     = "_rels/.rels"
)

Common filenames used in zip packages.

const (
    // Common strict
    OfficeDocumentTypeStrict     = "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument"
    StylesTypeStrict             = "http://purl.oclc.org/ooxml/officeDocument/relationships/styles"
    ThemeTypeStrict              = "http://purl.oclc.org/ooxml/officeDocument/relationships/theme"
    SettingsTypeStrict           = "http://purl.oclc.org/ooxml/officeDocument/relationships/settings"
    ImageTypeStrict              = "http://purl.oclc.org/ooxml/officeDocument/relationships/image"
    CommentsTypeStrict           = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"
    ThumbnailTypeStrict          = "http://purl.oclc.org/ooxml/officeDocument/relationships/metadata/thumbnail"
    DrawingTypeStrict            = "http://purl.oclc.org/ooxml/officeDocument/relationships/drawing"
    ChartTypeStrict              = "http://purl.oclc.org/ooxml/officeDocument/relationships/chart"
    ExtendedPropertiesTypeStrict = "http://purl.oclc.org/ooxml/officeDocument/relationships/extendedProperties"
    CustomXMLTypeStrict          = "http://purl.oclc.org/ooxml/officeDocument/relationships/customXml"

    // SML strict
    WorksheetTypeStrict    = "http://purl.oclc.org/ooxml/officeDocument/relationships/worksheet"
    SharedStingsTypeStrict = "http://purl.oclc.org/ooxml/officeDocument/relationships/sharedStrings"
    TableTypeStrict        = "http://purl.oclc.org/ooxml/officeDocument/relationships/table"

    // WML strict
    HeaderTypeStrict      = "http://purl.oclc.org/ooxml/officeDocument/relationships/header"
    FooterTypeStrict      = "http://purl.oclc.org/ooxml/officeDocument/relationships/footer"
    NumberingTypeStrict   = "http://purl.oclc.org/ooxml/officeDocument/relationships/numbering"
    FontTableTypeStrict   = "http://purl.oclc.org/ooxml/officeDocument/relationships/fontTable"
    WebSettingsTypeStrict = "http://purl.oclc.org/ooxml/officeDocument/relationships/webSettings"
    FootNotesTypeStrict   = "http://purl.oclc.org/ooxml/officeDocument/relationships/footnotes"
    EndNotesTypeStrict    = "http://purl.oclc.org/ooxml/officeDocument/relationships/endnotes"

    // PML strict
    SlideTypeStrict = "http://purl.oclc.org/ooxml/officeDocument/relationships/slide"

    // VML strict
    VMLDrawingTypeStrict = "http://purl.oclc.org/ooxml/officeDocument/relationships/vmlDrawing"

    // Common
    OfficeDocumentType     = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
    StylesType             = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
    ThemeType              = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"
    ThemeContentType       = "application/vnd.openxmlformats-officedocument.theme+xml"
    SettingsType           = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"
    ImageType              = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
    CommentsType           = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
    CommentsContentType    = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
    ThumbnailType          = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"
    DrawingType            = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
    DrawingContentType     = "application/vnd.openxmlformats-officedocument.drawing+xml"
    ChartType              = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
    ChartContentType       = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
    HyperLinkType          = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
    ExtendedPropertiesType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
    CorePropertiesType     = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
    CustomPropertiesType   = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"
    CustomXMLType          = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"

    // SML
    WorksheetType            = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
    WorksheetContentType     = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
    SharedStingsType         = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
    SharedStringsContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
    SMLStyleSheetContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
    TableType                = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
    TableContentType         = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
    ViewPropertiesType       = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps"
    TableStylesType          = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles"

    // WML
    HeaderType      = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"
    FooterType      = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"
    NumberingType   = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"
    FontTableType   = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"
    WebSettingsType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"
    FootNotesType   = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
    EndNotesType    = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"

    // PML
    SlideType                  = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"
    SlideContentType           = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml"
    SlideMasterType            = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster"
    SlideMasterContentType     = "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"
    SlideLayoutType            = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"
    SlideLayoutContentType     = "application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"
    PresentationPropertiesType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps"

    // VML
    VMLDrawingType        = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"
    VMLDrawingContentType = "application/vnd.openxmlformats-officedocument.vmlDrawing"
)

Consts for content types used throughout the package

const MinGoVersion = requires_go_18

MinGoVersion is used to cause a compile time error if unioffice is compiled with an older version of go. Specifically it requires a feature in go 1.8 regarding collecting all attributes from arbitrary xml used in decode unioffice.XSDAny.

Variables

var Log = log.Printf

Log is used to log content from within the library. The intent is to use logging sparingly, preferring to return an error. At the very least this allows redirecting logs to somewhere more appropriate than stdout.

func AbsoluteFilename Uses

func AbsoluteFilename(dt DocType, typ string, index int) string

AbsoluteFilename returns the full path to a file from the root of the zip container. Index is used in some cases for files which there may be more than one of (e.g. worksheets/drawings/charts)

func AbsoluteImageFilename Uses

func AbsoluteImageFilename(dt DocType, index int, fileExtension string) string

AbsoluteImageFilename returns the full path to an image from the root of the zip container.

func AddPreserveSpaceAttr Uses

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 Uses

func Bool(v bool) *bool

Bool returns a copy of v as a pointer.

func DisableLogging Uses

func DisableLogging()

DisableLogging sets the Log function to a no-op so that any log messages are silently discarded.

func Float32 Uses

func Float32(v float32) *float32

Float32 returns a copy of v as a pointer.

func Float64 Uses

func Float64(v float64) *float64

Float64 returns a copy of v as a pointer.

func Int32 Uses

func Int32(v int32) *int32

Int32 returns a copy of v as a pointer.

func Int64 Uses

func Int64(v int64) *int64

Int64 returns a copy of v as a pointer.

func Int8 Uses

func Int8(v int8) *int8

Int8 returns a copy of v as a pointer.

func NeedsSpacePreserve Uses

func NeedsSpacePreserve(s string) bool

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

func RegisterConstructor Uses

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

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

func RelativeFilename Uses

func RelativeFilename(dt DocType, relToTyp, typ string, index int) string

RelativeFilename returns a filename relative to the source file referenced from a relationships file. Index is used in some cases for files which there may be more than one of (e.g. worksheets/drawings/charts)

func String Uses

func String(v string) *string

String returns a copy of v as a pointer.

func Stringf Uses

func Stringf(f string, args ...interface{}) *string

Stringf formats according to a format specifier and returns a pointer to the resulting string.

func Uint16 Uses

func Uint16(v uint16) *uint16

Uint16 returns a copy of v as a pointer.

func Uint32 Uses

func Uint32(v uint32) *uint32

Uint32 returns a copy of v as a pointer.

func Uint64 Uses

func Uint64(v uint64) *uint64

Uint64 returns a copy of v as a pointer.

func Uint8 Uses

func Uint8(v uint8) *uint8

Uint8 returns a copy of v as a pointer.

type Any Uses

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 Uses

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 DocType Uses

type DocType byte

DocType represents one of the three document types supported (docx/xlsx/pptx)

const (
    Unknown DocType = iota
    DocTypeSpreadsheet
    DocTypeDocument
    DocTypePresentation
)

Document Type constants

type XSDAny Uses

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 Uses

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

MarshalXML implements the xml.Marshaler interface.

func (*XSDAny) UnmarshalXML Uses

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

UnmarshalXML implements the xml.Unmarshaler interface.

Directories

PathSynopsis
algo
chart
cmd/catdoc
cmd/csv2xlsx
cmd/docx2md
cmd/test-open-write
cmd/unprotect-xlsx
cmd/xlsx2csv
colorPackage color provides color handling structures and functions for use across all of the document types.
commonPackage common contains wrapper types and utilities common to all of the OOXML document formats.
common/licensePackage license helps manage commercial licenses and check if they are valid for the version of unidoc used.
documentPackage document provides creation, reading, and writing of ECMA 376 Open Office XML documents.
drawing
_examples/document/doc-custom-properties
_examples/document/doc-properties
_examples/document/edit-document
_examples/document/fill-out-form
_examples/document/header-footer
_examples/document/header-footer-multiple
_examples/document/hyperlink
_examples/document/image
_examples/document/line-spacing
_examples/document/mail-merge
_examples/document/page-numbers
_examples/document/pdf-export-ole
_examples/document/simple
_examples/document/tables
_examples/document/toc
_examples/document/toc-generation-ole
_examples/document/use-template
_examples/presentation/complex
_examples/presentation/image
_examples/presentation/simple
_examples/presentation/use-template
_examples/spreadsheet/bar-chart
_examples/spreadsheet/borders
_examples/spreadsheet/bubble-chart
_examples/spreadsheet/comments
_examples/spreadsheet/complex
_examples/spreadsheet/conditional-formatting
_examples/spreadsheet/formula
_examples/spreadsheet/formula-evaluation
_examples/spreadsheet/freeze-rows-cols
_examples/spreadsheet/image
_examples/spreadsheet/insert-rows
_examples/spreadsheet/line-chart
_examples/spreadsheet/line-chart-3d
_examples/spreadsheet/line-chart-no-data
_examples/spreadsheet/lots-of-rows
_examples/spreadsheet/merged
_examples/spreadsheet/multiple-charts
_examples/spreadsheet/named-cells
_examples/spreadsheet/named-ranges
_examples/spreadsheet/number-date-time-formats
_examples/spreadsheet/pie-chart
_examples/spreadsheet/radar-chart
_examples/spreadsheet/rich-text
_examples/spreadsheet/rotated-cells
_examples/spreadsheet/shared-formula
_examples/spreadsheet/simple
_examples/spreadsheet/sort-filter
_examples/spreadsheet/surface-chart
_examples/spreadsheet/validation
_examples/spreadsheet/wrapped-text
internal/wildcard
measurement
presentation
schema/purl.org/dc/elements
schema/purl.org/dc/terms
schema/soo/dml
schema/soo/dml/chart
schema/soo/dml/chartDrawing
schema/soo/dml/diagram
schema/soo/dml/lockedCanvas
schema/soo/dml/picture
schema/soo/dml/spreadsheetDrawing
schema/soo/ofc/custom_properties
schema/soo/ofc/docPropsVTypes
schema/soo/ofc/extended_properties
schema/soo/ofc/math
schema/soo/ofc/relationships
schema/soo/ofc/sharedTypes
schema/soo/pkg/content_types
schema/soo/pkg/metadata/core_properties
schema/soo/pkg/relationships
schema/soo/pml
schema/soo/schemaLibrary
schema/soo/sml
schema/soo/wml
schema/urn/schemas_microsoft_com/office/excel
schema/urn/schemas_microsoft_com/office/powerpoint
schema/urn/schemas_microsoft_com/office/word
schema/urn/schemas_microsoft_com/vml
spreadsheet
spreadsheet/formatPackage format provides support for parsing and evaluating spreadsheetml/Excel number formats.
spreadsheet/formulaPackage formula provides formula parsing and evaluation.
spreadsheet/reference
testhelper
vmldrawing
zippkg

Package unioffice imports 8 packages (graph) and is imported by 50 packages. Updated 2019-11-05. Refresh now. Tools for package owners.