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

package common

import "github.com/unidoc/unioffice/common"

Package common contains wrapper types and utilities common to all of the OOXML document formats.

Package common contains common properties used by the subpackages.



Package Files

appproperties.go contenttypes.go coreproperties.go customproperties.go doc.go docbase.go helpers.go image.go relationship.go relationships.go theme.go time.go version.go


const Version = "1.2.0"

Version holds version information, when bumping this make sure to bump the released at stamp also.


var ReleasedAt = time.Date(releaseYear, releaseMonth, releaseDay, releaseHour, releaseMin, 0, 0, time.UTC)

func AddImageToZip Uses

func AddImageToZip(z *zip.Writer, img ImageRef, imageNum int, dt unioffice.DocType) error

AddImageToZip adds an image (either from bytes or from disk) and adds it to the zip file.

func UtcTimeFormat Uses

func UtcTimeFormat(t time.Time) string

type AppProperties Uses

type AppProperties struct {
    // contains filtered or unexported fields

AppProperties contains properties specific to the document and the application that created it.

func NewAppProperties Uses

func NewAppProperties() AppProperties

NewAppProperties constructs a new AppProperties.

func (AppProperties) Application Uses

func (a AppProperties) Application() string

Application returns the name of the application that created the document. For gooxml created documents, it defaults to github.com/unidoc/unioffice

func (AppProperties) ApplicationVersion Uses

func (a AppProperties) ApplicationVersion() string

ApplicationVersion returns the version of the application that created the document.

func (AppProperties) Company Uses

func (a AppProperties) Company() string

Company returns the name of the company that created the document. For gooxml created documents, it defaults to github.com/unidoc/unioffice

func (AppProperties) SetApplication Uses

func (a AppProperties) SetApplication(s string)

SetApplication sets the name of the application that created the document.

func (AppProperties) SetApplicationVersion Uses

func (a AppProperties) SetApplicationVersion(s string)

SetApplicationVersion sets the version of the application that created the document. Per MS, the verison string mut be in the form 'XX.YYYY'.

func (AppProperties) SetCompany Uses

func (a AppProperties) SetCompany(s string)

SetCompany sets the name of the company that created the document.

func (AppProperties) SetDocSecurity Uses

func (a AppProperties) SetDocSecurity(v int32)

SetDocSecurity sets the document security flag.

func (AppProperties) SetLinksUpToDate Uses

func (a AppProperties) SetLinksUpToDate(v bool)

SetLinksUpToDate sets the links up to date flag.

func (AppProperties) X Uses

func (a AppProperties) X() *extended_properties.Properties

X returns the inner wrapped XML type.

type ContentTypes Uses

type ContentTypes struct {
    // contains filtered or unexported fields

ContentTypes is the top level "[Content_Types].xml" in a zip package.

func NewContentTypes Uses

func NewContentTypes() ContentTypes

NewContentTypes returns a wrapper around a newly constructed content-types.

func (ContentTypes) AddDefault Uses

func (c ContentTypes) AddDefault(fileExtension string, contentType string)

AddDefault registers a default content type for a given file extension.

func (ContentTypes) AddOverride Uses

func (c ContentTypes) AddOverride(path, contentType string)

AddOverride adds an override content type for a given path name.

func (ContentTypes) CopyOverride Uses

func (c ContentTypes) CopyOverride(path, newPath string)

CopyOverride copies override content type for a given `path` and puts it with a path `newPath`.

func (ContentTypes) EnsureDefault Uses

func (c ContentTypes) EnsureDefault(ext, contentType string)

EnsureDefault esnures that an extension and default content type exist, adding it if necessary.

func (ContentTypes) EnsureOverride Uses

func (c ContentTypes) EnsureOverride(path, contentType string)

EnsureOverride ensures that an override for the given path exists, adding it if necessary

func (ContentTypes) RemoveOverride Uses

func (c ContentTypes) RemoveOverride(path string)

RemoveOverride removes an override given a path.

func (ContentTypes) X Uses

func (c ContentTypes) X() *content_types.Types

X returns the inner raw content types.

type CoreProperties Uses

type CoreProperties struct {
    // contains filtered or unexported fields

CoreProperties contains document specific properties.


doc, _ := document.Open("document.docx")
cp := doc.CoreProperties
// Reading Properties
fmt.Println("Title:", cp.Title())
fmt.Println("Author:", cp.Author())
fmt.Println("Description:", cp.Description())
fmt.Println("Last Modified By:", cp.LastModifiedBy())
fmt.Println("Category:", cp.Category())
fmt.Println("Content Status:", cp.ContentStatus())
fmt.Println("Created:", cp.Created())
fmt.Println("Modified:", cp.Modified())

// Setting Properties
cp.SetTitle("CP Invoices")
cp.SetAuthor("John Doe")
cp.SetLastModifiedBy("Jane Smith")

func NewCoreProperties Uses

func NewCoreProperties() CoreProperties

NewCoreProperties constructs a new CoreProperties.

func (CoreProperties) Author Uses

func (c CoreProperties) Author() string

Author returns the author of the document

func (CoreProperties) Category Uses

func (c CoreProperties) Category() string

Category returns the category of the document

func (CoreProperties) ContentStatus Uses

func (c CoreProperties) ContentStatus() string

ContentStatus returns the content status of the document (e.g. "Final", "Draft")

func (CoreProperties) Created Uses

func (c CoreProperties) Created() time.Time

Created returns the time that the document was created.

func (CoreProperties) Description Uses

func (c CoreProperties) Description() string

Description returns the description of the document

func (CoreProperties) LastModifiedBy Uses

func (c CoreProperties) LastModifiedBy() string

LastModifiedBy returns the name of the last person to modify the document

func (CoreProperties) Modified Uses

func (c CoreProperties) Modified() time.Time

Modified returns the time that the document was modified.

func (CoreProperties) SetAuthor Uses

func (c CoreProperties) SetAuthor(s string)

SetAuthor records the author of the document.

func (CoreProperties) SetCategory Uses

func (c CoreProperties) SetCategory(s string)

SetCategory records the category of the document.

func (CoreProperties) SetContentStatus Uses

func (c CoreProperties) SetContentStatus(s string)

SetContentStatus records the content status of the document.

func (CoreProperties) SetCreated Uses

func (c CoreProperties) SetCreated(t time.Time)

SetCreated sets the time that the document was created.

func (CoreProperties) SetDescription Uses

func (c CoreProperties) SetDescription(s string)

SetDescription records the description of the document.

func (CoreProperties) SetLanguage Uses

func (c CoreProperties) SetLanguage(s string)

SetLanguage records the language of the document.

func (CoreProperties) SetLastModifiedBy Uses

func (c CoreProperties) SetLastModifiedBy(s string)

SetLastModifiedBy records the last person to modify the document.

func (CoreProperties) SetModified Uses

func (c CoreProperties) SetModified(t time.Time)

SetModified sets the time that the document was modified.

func (CoreProperties) SetTitle Uses

func (c CoreProperties) SetTitle(s string)

SetTitle records the title of the document.

func (CoreProperties) Title Uses

func (c CoreProperties) Title() string

Title returns the Title of the document

func (CoreProperties) X Uses

func (c CoreProperties) X() *core_properties.CoreProperties

X returns the inner wrapped XML type.

type CustomProperties Uses

type CustomProperties struct {
    // contains filtered or unexported fields

CustomProperties contains document specific properties.


doc, _ := document.Open("document.docx")

cp := doc.CustomProperties
// You can read properties from the document
fmt.Println("AppVersion", *cp.GetPropertyByName("AppVersion").Lpwstr)
fmt.Println("category", *cp.GetPropertyByName("category").Lpwstr)
fmt.Println("contentStatus", *cp.GetPropertyByName("contentStatus").Lpwstr)
fmt.Println("HyperlinksChanged", *cp.GetPropertyByName("HyperlinksChanged").Bool)
fmt.Println("Non-existent", cp.GetPropertyByName("nonexistentproperty"))

// And change them as well
cp.SetPropertyAsLpwstr("Another text property", "My text value") // text
cp.SetPropertyAsI4("Another integer number property", 42)        // int23
cp.SetPropertyAsR8("Another float number property", 3.14)        // float64
cp.SetPropertyAsDate("Another date property", time.Now())        // date


func NewCustomProperties Uses

func NewCustomProperties() CustomProperties

NewCustomProperties constructs a new CustomProperties.

func (CustomProperties) GetPropertyByName Uses

func (c CustomProperties) GetPropertyByName(name string) CustomProperty

func (CustomProperties) PropertiesList Uses

func (c CustomProperties) PropertiesList() []*custom_properties.CT_Property

func (CustomProperties) SetPropertyAsArray Uses

func (c CustomProperties) SetPropertyAsArray(name string, array *docPropsVTypes.Array)

func (CustomProperties) SetPropertyAsBlob Uses

func (c CustomProperties) SetPropertyAsBlob(name, blob string)

func (CustomProperties) SetPropertyAsBool Uses

func (c CustomProperties) SetPropertyAsBool(name string, b bool)

func (CustomProperties) SetPropertyAsBstr Uses

func (c CustomProperties) SetPropertyAsBstr(name string, bstr string)

func (CustomProperties) SetPropertyAsClsid Uses

func (c CustomProperties) SetPropertyAsClsid(name string, clsid string)

func (CustomProperties) SetPropertyAsCy Uses

func (c CustomProperties) SetPropertyAsCy(name string, cy string)

func (CustomProperties) SetPropertyAsDate Uses

func (c CustomProperties) SetPropertyAsDate(name string, date time.Time)

func (CustomProperties) SetPropertyAsDecimal Uses

func (c CustomProperties) SetPropertyAsDecimal(name string, decimal float64)

func (CustomProperties) SetPropertyAsEmpty Uses

func (c CustomProperties) SetPropertyAsEmpty(name string)

func (CustomProperties) SetPropertyAsError Uses

func (c CustomProperties) SetPropertyAsError(name string, error string)

func (CustomProperties) SetPropertyAsFiletime Uses

func (c CustomProperties) SetPropertyAsFiletime(name string, filetime time.Time)

func (CustomProperties) SetPropertyAsI1 Uses

func (c CustomProperties) SetPropertyAsI1(name string, i1 int8)

func (CustomProperties) SetPropertyAsI2 Uses

func (c CustomProperties) SetPropertyAsI2(name string, i2 int16)

func (CustomProperties) SetPropertyAsI4 Uses

func (c CustomProperties) SetPropertyAsI4(name string, i4 int32)

func (CustomProperties) SetPropertyAsI8 Uses

func (c CustomProperties) SetPropertyAsI8(name string, i8 int64)

func (CustomProperties) SetPropertyAsInt Uses

func (c CustomProperties) SetPropertyAsInt(name string, i int)

func (CustomProperties) SetPropertyAsLpstr Uses

func (c CustomProperties) SetPropertyAsLpstr(name string, lpstr string)

func (CustomProperties) SetPropertyAsLpwstr Uses

func (c CustomProperties) SetPropertyAsLpwstr(name string, lpwstr string)

func (CustomProperties) SetPropertyAsNull Uses

func (c CustomProperties) SetPropertyAsNull(name string)

func (CustomProperties) SetPropertyAsOblob Uses

func (c CustomProperties) SetPropertyAsOblob(name, oblob string)

func (CustomProperties) SetPropertyAsOstorage Uses

func (c CustomProperties) SetPropertyAsOstorage(name string, ostorage string)

func (CustomProperties) SetPropertyAsOstream Uses

func (c CustomProperties) SetPropertyAsOstream(name string, ostream string)

func (CustomProperties) SetPropertyAsR4 Uses

func (c CustomProperties) SetPropertyAsR4(name string, r4 float32)

func (CustomProperties) SetPropertyAsR8 Uses

func (c CustomProperties) SetPropertyAsR8(name string, r8 float64)

func (CustomProperties) SetPropertyAsStorage Uses

func (c CustomProperties) SetPropertyAsStorage(name string, storage string)

func (CustomProperties) SetPropertyAsStream Uses

func (c CustomProperties) SetPropertyAsStream(name string, stream string)

func (CustomProperties) SetPropertyAsUi1 Uses

func (c CustomProperties) SetPropertyAsUi1(name string, ui1 uint8)

func (CustomProperties) SetPropertyAsUi2 Uses

func (c CustomProperties) SetPropertyAsUi2(name string, ui2 uint16)

func (CustomProperties) SetPropertyAsUi4 Uses

func (c CustomProperties) SetPropertyAsUi4(name string, ui4 uint32)

func (CustomProperties) SetPropertyAsUi8 Uses

func (c CustomProperties) SetPropertyAsUi8(name string, ui8 uint64)

func (CustomProperties) SetPropertyAsUint Uses

func (c CustomProperties) SetPropertyAsUint(name string, ui uint)

func (CustomProperties) SetPropertyAsVector Uses

func (c CustomProperties) SetPropertyAsVector(name string, vector *docPropsVTypes.Vector)

func (CustomProperties) SetPropertyAsVstream Uses

func (c CustomProperties) SetPropertyAsVstream(name string, vstream *docPropsVTypes.Vstream)

func (CustomProperties) X Uses

func (c CustomProperties) X() *custom_properties.Properties

X returns the inner wrapped XML type.

type CustomProperty Uses

type CustomProperty *custom_properties.CT_Property

CustomProperty contains document specific property

type DocBase Uses

type DocBase struct {
    ContentTypes     ContentTypes
    AppProperties    AppProperties
    Rels             Relationships
    CoreProperties   CoreProperties
    CustomProperties CustomProperties
    Thumbnail        image.Image // thumbnail preview of the document

    Images     []ImageRef
    ExtraFiles []ExtraFile
    TmpPath    string // path where temporary files are stored when opening documents


DocBase is the type embedded in in the Document/Workbook/Presentation types that contains members common to all.

func (*DocBase) AddExtraFileFromZip Uses

func (d *DocBase) AddExtraFileFromZip(f *zip.File) error

AddExtraFileFromZip is used when reading an unsupported file from an OOXML file. This ensures that unsupported file content will at least round-trip correctly.

func (*DocBase) WriteExtraFiles Uses

func (d *DocBase) WriteExtraFiles(z *zip.Writer) error

WriteExtraFiles writes the extra files to the zip package.

type ExtraFile Uses

type ExtraFile struct {
    ZipPath  string
    DiskPath string

ExtraFile is an unsupported file type extracted from, or to be written to a zip package

type Hyperlink Relationship

Hyperlink is just an appropriately configured relationship.

type Image Uses

type Image struct {
    Size   image.Point
    Format string
    Path   string
    Data   *[]byte

Image is a container for image information. It's used as we need format and and size information to use images. It contains either the filesystem path to the image, or the image itself.

func ImageFromBytes Uses

func ImageFromBytes(data []byte) (Image, error)

ImageFromBytes returns an Image struct for an in-memory image. You can also construct an Image directly if the file and size are known.

func ImageFromFile Uses

func ImageFromFile(path string) (Image, error)

ImageFromFile reads an image from a file on disk. It doesn't keep the image in memory and only reads it to determine the format and size. You can also construct an Image directly if the file and size are known.

type ImageRef Uses

type ImageRef struct {
    // contains filtered or unexported fields

ImageRef is a reference to an image within a document.

func MakeImageRef Uses

func MakeImageRef(img Image, d *DocBase, rels Relationships) ImageRef

MakeImageRef constructs an image reference which is a reference to a particular image file inside a document. The same image can be used multiple times in a document by re-use the ImageRef.

func (ImageRef) Data Uses

func (i ImageRef) Data() *[]byte

Data returns the data of an image file, if any.

func (ImageRef) Format Uses

func (i ImageRef) Format() string

Format returns the format of the underlying image

func (ImageRef) Path Uses

func (i ImageRef) Path() string

Path returns the path to an image file, if any.

func (ImageRef) RelID Uses

func (i ImageRef) RelID() string

RelID returns the relationship ID.

func (ImageRef) RelativeHeight Uses

func (i ImageRef) RelativeHeight(w measurement.Distance) measurement.Distance

RelativeHeight returns the relative height of an image given a fixed width. This is used when setting image to a fixed width to calculate the height required to keep the same image aspect ratio.

func (ImageRef) RelativeWidth Uses

func (i ImageRef) RelativeWidth(h measurement.Distance) measurement.Distance

RelativeWidth returns the relative width of an image given a fixed height. This is used when setting image to a fixed height to calculate the width required to keep the same image aspect ratio.

func (*ImageRef) SetRelID Uses

func (i *ImageRef) SetRelID(id string)

func (ImageRef) Size Uses

func (i ImageRef) Size() image.Point

Size returns the size of an image

type Relationship Uses

type Relationship struct {
    // contains filtered or unexported fields

Relationship is a relationship within a .rels file.

func NewRelationship Uses

func NewRelationship() Relationship

NewRelationship constructs a new relationship.

func (Relationship) ID Uses

func (r Relationship) ID() string

ID returns the ID of a relationship.

func (Relationship) SetTarget Uses

func (r Relationship) SetTarget(s string)

SetTarget set the target (path) of a relationship.

func (Relationship) String Uses

func (r Relationship) String() string

func (Relationship) Target Uses

func (r Relationship) Target() string

Target returns the target (path) of a relationship.

func (Relationship) Type Uses

func (r Relationship) Type() string

Type returns the type of a relationship.

func (Relationship) X Uses

func (r Relationship) X() *relationships.Relationship

X returns the inner wrapped XML type.

type Relationships Uses

type Relationships struct {
    // contains filtered or unexported fields

Relationships represents a .rels file.

func NewRelationships Uses

func NewRelationships() Relationships

NewRelationships creates a new relationship wrapper.

func NewRelationshipsCopy Uses

func NewRelationshipsCopy(rels Relationships) Relationships

NewRelationshipsCopy creates a new relationships wrapper as a copy of passed in instance.

func (Relationships) AddAutoRelationship Uses

func (r Relationships) AddAutoRelationship(dt unioffice.DocType, src string, idx int, ctype string) Relationship

AddAutoRelationship adds a relationship with an automatically generated filename based off of the type. It should be preferred over AddRelationship to ensure consistent filenames are maintained.

func (r Relationships) AddHyperlink(target string) Hyperlink

AddHyperlink adds an external hyperlink relationship.

func (Relationships) AddRelationship Uses

func (r Relationships) AddRelationship(target, ctype string) Relationship

AddRelationship adds a relationship.

func (Relationships) Clear Uses

func (r Relationships) Clear()

Clear removes any existing relationships.

func (Relationships) CopyRelationship Uses

func (r Relationships) CopyRelationship(idAttr string) (Relationship, bool)

CopyRelationship copies the relationship.

func (Relationships) FindRIDForN Uses

func (r Relationships) FindRIDForN(i int, t string) string

FindRIDForN returns the relationship ID for the i'th relationship of type t.

func (Relationships) IsEmpty Uses

func (r Relationships) IsEmpty() bool

IsEmpty returns true if there are no relationships.

func (Relationships) Relationships Uses

func (r Relationships) Relationships() []Relationship

Relationships returns a slice of all of the relationships.

func (Relationships) Remove Uses

func (r Relationships) Remove(rel Relationship) bool

Remove removes an existing relationship.

func (Relationships) X Uses

func (r Relationships) X() *relationships.Relationships

X returns the underlying raw XML data.

type Theme Uses

type Theme struct {
    // contains filtered or unexported fields

Theme is a drawingml theme.

func NewTheme Uses

func NewTheme() Theme

NewTheme constructs a new theme.

func (Theme) X Uses

func (t Theme) X() *dml.Theme

X returns the inner wrapped XML type.


licensePackage license helps manage commercial licenses and check if they are valid for the version of unidoc used.

Package common imports 21 packages (graph) and is imported by 18 packages. Updated 2019-08-05. Refresh now. Tools for package owners.