Documentation
¶
Overview ¶
Package goffice 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/dhx007/goffice/document, unidoc/goffice/spreadsheet and github.com/dhx007/goffice/presentation.
Example (Document) ¶
package main
import (
"github.com/dhx007/goffice/document"
)
func main() {
// see the github.com/dhx007/goffice/document documentation or _examples/document
// for more examples
doc := document.New()
doc.AddParagraph().AddRun().AddText("Hello World!")
doc.SaveToFile("document.docx")
}
Example (Spreadsheeet) ¶
package main
import (
"github.com/dhx007/goffice/spreadsheet"
)
func main() {
// see the github.com/dhx007/goffice/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 ¶
- Constants
- Variables
- func AbsoluteFilename(dt DocType, typ string, index int) string
- func AbsoluteImageFilename(dt DocType, index int, fileExtension string) string
- func AddPreserveSpaceAttr(se *xml.StartElement, s string)
- func Bool(v bool) *bool
- func DisableLogging()
- func Float32(v float32) *float32
- func Float64(v float64) *float64
- func Int32(v int32) *int32
- func Int64(v int64) *int64
- func Int8(v int8) *int8
- func NeedsSpacePreserve(s string) bool
- func RegisterConstructor(ns, name string, fn interface{})
- func RelativeFilename(dt DocType, relToTyp, typ string, index int) string
- func RelativeImageFilename(dt DocType, relToTyp, typ string, index int, fileExtension string) string
- func String(v string) *string
- func Stringf(f string, args ...interface{}) *string
- func Uint16(v uint16) *uint16
- func Uint32(v uint32) *uint32
- func Uint64(v uint64) *uint64
- func Uint8(v uint8) *uint8
- type Any
- type DocType
- type XSDAny
Examples ¶
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" // Deprecated: Renamed to SharedStringsTypeStrict, will be removed in next major version. TableTypeStrict = "http://purl.oclc.org/ooxml/officeDocument/relationships/table" // WML strict HeaderTypeStrict = "http://purl.oclc.org/ooxml/officeDocument/relationships/header" 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" TableStylesType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles" ViewPropertiesType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps" // SML WorksheetType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" WorksheetContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" // Deprecated: Renamed to SharedStringsType, will be removed in next major version. 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" // WML HeaderType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" 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" HandoutMasterType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/handoutMaster" NotesMasterType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster" // 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 goffice 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 goffice.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.
Functions ¶
func AbsoluteFilename ¶
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 ¶
AbsoluteImageFilename returns the full path to an image from the root of the zip container.
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 DisableLogging ¶
func DisableLogging()
DisableLogging sets the Log function to a no-op so that any log messages are silently discarded.
func NeedsSpacePreserve ¶
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 RelativeFilename ¶
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 RelativeImageFilename ¶
func RelativeImageFilename(dt DocType, relToTyp, typ string, index int, fileExtension string) string
RelativeImageFilename returns an image filename relative to the source file referenced from a relationships file. It is identical to RelativeFilename but is used particularly for images in order to handle different image formats.
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 DocType ¶
type DocType byte
DocType represents one of the three document types supported (docx/xlsx/pptx)
type XSDAny ¶
XSDAny is used to marshal/unmarshal xsd:any types in the OOXML schema.
func (*XSDAny) MarshalXML ¶
MarshalXML implements the xml.Marshaler interface.
func (*XSDAny) UnmarshalXML ¶
UnmarshalXML implements the xml.Unmarshaler interface.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
document/doc-custom-properties
command
|
|
|
document/doc-properties
command
|
|
|
document/edit-document
command
|
|
|
document/endnotes_footnotes
command
|
|
|
document/fill-out-form
command
|
|
|
document/header-footer
command
|
|
|
document/header-footer-multiple
command
|
|
|
document/hyperlink
command
|
|
|
document/image
command
|
|
|
document/line-spacing
command
|
|
|
document/mail-merge
command
|
|
|
document/page-numbers
command
|
|
|
document/paragraphs_in_table
command
|
|
|
document/pdf-export-ole
command
|
|
|
document/set-strict
command
|
|
|
document/simple
command
|
|
|
document/tables
command
|
|
|
document/toc
command
|
|
|
document/toc-generation-ole
command
|
|
|
document/use-template
command
|
|
|
presentation/complex
command
|
|
|
presentation/image
command
|
|
|
presentation/simple
command
|
|
|
presentation/use-template
command
|
|
|
spreadsheet/bar-chart
command
|
|
|
spreadsheet/borders
command
|
|
|
spreadsheet/bubble-chart
command
|
|
|
spreadsheet/cells-with-empty
command
|
|
|
spreadsheet/comments
command
|
|
|
spreadsheet/complex
command
|
|
|
spreadsheet/flatten
command
|
|
|
spreadsheet/formula
command
|
|
|
spreadsheet/formula-evaluation
command
|
|
|
spreadsheet/freeze-rows-cols
command
|
|
|
spreadsheet/image
command
|
|
|
spreadsheet/insert-rows
command
|
|
|
spreadsheet/line-chart
command
|
|
|
spreadsheet/line-chart-3d
command
|
|
|
spreadsheet/line-chart-no-data
command
|
|
|
spreadsheet/lots-of-rows
command
|
|
|
spreadsheet/merged
command
|
|
|
spreadsheet/multiple-charts
command
|
|
|
spreadsheet/named-cells
command
|
|
|
spreadsheet/named-ranges
command
|
|
|
spreadsheet/pie-chart
command
|
|
|
spreadsheet/radar-chart
command
|
|
|
spreadsheet/remove-column
command
|
|
|
spreadsheet/rich-text
command
|
|
|
spreadsheet/rotated-cells
command
|
|
|
spreadsheet/shared-formula
command
|
|
|
spreadsheet/simple
command
|
|
|
spreadsheet/sort-filter
command
|
|
|
spreadsheet/surface-chart
command
|
|
|
spreadsheet/validation
command
|
|
|
spreadsheet/wrapped-text
command
|
|
|
cmd
|
|
|
catdoc
command
|
|
|
csv2xlsx
command
|
|
|
docx2md
command
|
|
|
test-open-write
command
|
|
|
unprotect-xlsx
command
|
|
|
xlsx2csv
command
|
|
|
Package color provides color handling structures and functions for use across all of the document types.
|
Package color provides color handling structures and functions for use across all of the document types. |
|
Package common contains wrapper types and utilities common to all of the OOXML document formats.
|
Package common contains wrapper types and utilities common to all of the OOXML document formats. |
|
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. |
|
internal
|
|
|
mergesort
Package mergesort provides an implementation for merge sort sorting algorithm
|
Package mergesort provides an implementation for merge sort sorting algorithm |
|
schema
|
|
|
format
Package format provides support for parsing and evaluating spreadsheetml/Excel number formats.
|
Package format provides support for parsing and evaluating spreadsheetml/Excel number formats. |
|
formula
Package formula provides formula parsing and evaluation.
|
Package formula provides formula parsing and evaluation. |
|
update
Package update contains definitions needed for updating references after removing rows/columns.
|
Package update contains definitions needed for updating references after removing rows/columns. |