oxml

package
v0.0.7-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package oxml provides utilities for working with Office Open XML (OOXML) documents, including functions related to encoding and decoding XML elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

type Body struct {
	XMLName  xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main body"`
	Children []DocumentChild
	SectPr   *CTSectPr
}

This element specifies the contents of the body of the document – the main document editing surface.

func NewBody

func NewBody() *Body

Use this function to initialize a new Body before adding content to it.

func (*Body) MarshalXML

func (b *Body) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)

MarshalXML implements the xml.Marshaler interface for the Body type. It encodes the Body to its corresponding XML representation.

func (*Body) UnmarshalXML

func (body *Body) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML implements the xml.Unmarshaler interface for the Body type. It decodes the XML representation of the Body.

type CTSectPr

type CTSectPr struct {
	Type      *SectionType    `xml:"type,omitempty"`
	PgSz      *PageSize       `xml:"pgSz,omitempty"`
	PgMar     *PageMargins    `xml:"pgMar,omitempty"`
	PgNumType *PageNumbering  `xml:"pgNumType,omitempty"`
	FormProt  *FormProtection `xml:"formProt,omitempty"`
	TextDir   *TextDirection  `xml:"textDirection,omitempty"`
	DocGrid   *DocGrid        `xml:"docGrid,omitempty"` // Add DocGrid field

}

CTSectPr represents the section properties of a Word document.

func (*CTSectPr) MarshalXML

func (sectPr *CTSectPr) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)

MarshalXML implements the xml.Marshaler interface for the CTSectPr type. It encodes the CTSectPr to its corresponding XML representation.

type CoreProperties

type CoreProperties struct {
	Category       string
	ContentStatus  string
	Created        string
	Creator        string
	Description    string
	Identifier     string
	Keywords       string
	LastModifiedBy string
	Modified       string
	Revision       string
	Subject        string
	Title          string
	Language       string
	Version        string
}

CoreProperties represents the core properties of a document, such as title, creator, and version. It is used to store metadata information about the document.

func LoadDocProps

func LoadDocProps(fileBytes []byte) (cp *CoreProperties, err error)

LoadDocProps decodes the provided XML data and returns a CoreProperties instance. It is used to load core properties from the document file.

Parameters:

  • fileBytes: The XML data representing the core properties of the document.

Returns:

  • cp: The CoreProperties instance containing the decoded core properties.
  • err: An error, if any occurred during the decoding process.

type DocGrid

type DocGrid struct {
	Type      string `xml:"type,attr,omitempty"`
	LinePitch int    `xml:"linePitch,attr,omitempty"`
	CharSpace int    `xml:"charSpace,attr,omitempty"`
}

DocGrid represents the document grid settings.

func (*DocGrid) MarshalXML

func (docGrid *DocGrid) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface for the DocGrid type. It encodes the DocGrid to its corresponding XML representation.

type Document

type Document struct {
	Body *Body
	// contains filtered or unexported fields
}

This element specifies the contents of a main document part in a WordprocessingML document.

func LoadDocXml

func LoadDocXml(fileName string, fileBytes []byte) (*Document, error)

LoadDocXml decodes the provided XML data and returns a Document instance. It is used to load the main document structure from the document file.

Parameters:

  • fileName: The name of the document file.
  • fileBytes: The XML data representing the main document structure.

Returns:

  • doc: The Document instance containing the decoded main document structure.
  • err: An error, if any occurred during the decoding process.

func (*Document) MarshalXML

func (doc *Document) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)

MarshalXML implements the xml.Marshaler interface for the Document type.

func (*Document) UnmarshalXML

func (doc *Document) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

UnmarshalXML implements the xml.Unmarshaler interface for the Document type.

type DocumentChild

type DocumentChild struct {
	Para  *elements.Paragraph
	Table *elements.Table
}

DocumentChild represents a child element within a Word document, which can be a Paragraph or a Table.

type ExtendedProperties

type ExtendedProperties struct {
	Application       string
	ScaleCrop         bool
	DocSecurity       int
	Company           string
	LinksUpToDate     bool
	HyperlinksChanged bool
	AppVersion        string
}

ExtendedProperties represents extended properties of a document, such as application details and statistics. It is used to store additional metadata information about the document.

type FormProtection

type FormProtection struct {
	Val string `xml:"val,attr,omitempty"`
}

FormProtection represents the form protection settings in a Word document.

func (*FormProtection) MarshalXML

func (formProt *FormProtection) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface for the FormProtection type. It encodes the FormProtection to its corresponding XML representation.

type HeadingPairs

type HeadingPairs struct {
	Vector Vector `xml:"HeadingPairs"`
}

HeadingPairs represents a set of heading pairs used in extended properties.

type PageMargins

type PageMargins struct {
	Left   int `xml:"left,attr,omitempty"`
	Right  int `xml:"right,attr,omitempty"`
	Gutter int `xml:"gutter,attr,omitempty"`
	Header int `xml:"header,attr,omitempty"`
	Top    int `xml:"top,attr,omitempty"`
	Footer int `xml:"footer,attr,omitempty"`
	Bottom int `xml:"bottom,attr,omitempty"` // Add Bottom attribute
}

PageMargins represents the page margins of a Word document.

func (*PageMargins) MarshalXML

func (pgMar *PageMargins) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface for the PageMargins type. It encodes the PageMargins to its corresponding XML representation.

type PageNumbering

type PageNumbering struct {
	Fmt string `xml:"fmt,attr,omitempty"`
}

PageNumbering represents the page numbering format in a Word document.

func (*PageNumbering) MarshalXML

func (pgNumType *PageNumbering) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface for the PageNumbering type. It encodes the PageNumbering to its corresponding XML representation.

type PageSize

type PageSize struct {
	W int `xml:"w,attr,omitempty"`
	H int `xml:"h,attr,omitempty"`
}

PageSize represents the page size of a Word document.

func (*PageSize) MarshalXML

func (pgSz *PageSize) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface for the PageSize type. It encodes the PageSize to its corresponding XML representation.

type Relationship

type Relationship struct {
	XMLName    xml.Name `xml:"Relationship"`
	ID         string   `xml:"Id,attr"`
	Type       string   `xml:"Type,attr"`
	Target     string   `xml:"Target,attr"`
	TargetMode string   `xml:"TargetMode,attr,omitempty"`
}

Relationship represents a relationship between elements in an Office Open XML (OOXML) document. It includes essential information such as ID, type, target, and target mode.

type Relationships

type Relationships struct {
	RelativePath  string          `xml:"-"`
	XMLName       xml.Name        `xml:"Relationships"`
	Xmlns         string          `xml:"xmlns,attr"`
	Relationships []*Relationship `xml:"Relationship"`
}

Relationships represents a collection of relationships in an OOXML document. It includes the relative path, XML namespace, and a slice of Relationship instances.

type RootDoc

type RootDoc struct {
	Path     string        // Path represents the path of the document.
	FileMap  sync.Map      // FileMap is a synchronized map for managing files related to the document.
	Document *Document     // Document is the main document structure.
	RootRels Relationships // RootRels represents relationships at the root level.
	DocRels  Relationships // DocRels represents relationships specific to the document.
	// contains filtered or unexported fields
}

RootDoc represents the root document of an Office Open XML (OOXML) document. It contains information about the document path, file map, the document structure, and relationships with other parts of the document.

func NewRootDoc

func NewRootDoc() *RootDoc

NewRootDoc creates a new instance of the RootDoc structure.

func (*RootDoc) AddEmptyParagraph

func (rd *RootDoc) AddEmptyParagraph() *elements.Paragraph

AddEmptyParagraph adds a new empty paragraph to the document. It returns the created Paragraph instance.

Returns:

  • p: The created Paragraph instance.

func (*RootDoc) AddHeading

func (rd *RootDoc) AddHeading(text string, level uint) (*elements.Paragraph, error)

Return a heading paragraph newly added to the end of the document. The heading paragraph will contain text and have its paragraph style determined by level. If level is 0, the style is set to Title. The style is set to Heading {level}. if level is outside the range 0-9, error will be returned

func (*RootDoc) AddParagraph

func (rd *RootDoc) AddParagraph(text string) *elements.Paragraph

AddParagraph adds a new paragraph with the specified text to the document. It returns the created Paragraph instance.

Parameters:

  • text: The text to be added to the paragraph.

Returns:

  • p: The created Paragraph instance.

func (*RootDoc) AddTable

func (rd *RootDoc) AddTable() *elements.Table

func (*RootDoc) Close

func (rd *RootDoc) Close() error

Close method is used to close the RootDoc. Currently, it does not perform any specific actions.

func (*RootDoc) Save

func (rd *RootDoc) Save() error

Save method saves the RootDoc to the specified file path.

func (*RootDoc) SaveTo

func (rd *RootDoc) SaveTo(fileName string) error

SaveTo method saves the RootDoc to the specified file path.

func (*RootDoc) Write

func (rd *RootDoc) Write(w io.Writer) error

Write method writes the RootDoc to an io.Writer.

func (*RootDoc) WriteTo

func (rd *RootDoc) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo to write the RootDoc to an io.Writer.

type SectionType

type SectionType struct {
	Val string `xml:"val,attr,omitempty"`
}

SectionType represents the type of section in a Word document.

func (*SectionType) MarshalXML

func (st *SectionType) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface for the SectionType type. It encodes the SectionType to its corresponding XML representation.

type TextDirection

type TextDirection struct {
	Val string `xml:"val,attr,omitempty"`
}

TextDirection represents the text direction settings in a Word document.

func (*TextDirection) MarshalXML

func (textDir *TextDirection) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface for the TextDirection type. It encodes the TextDirection to its corresponding XML representation.

type TitlesOfParts

type TitlesOfParts struct {
	Vector Vector `xml:"TitlesOfParts"`
}

TitlesOfParts represents a set of titles of parts used in extended properties.

type Variant

type Variant struct {
	LPStr string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes lpstr,omitempty"`
	I4    int    `xml:"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes i4,omitempty"`
}

Variant represents a variant structure used in extended properties.

type Vector

type Vector struct {
	Size     int       `xml:"size,attr"`
	BaseType string    `xml:"baseType,attr"`
	Variant  []Variant `xml:"variant,omitempty"`
}

Vector represents a vector structure used in extended properties.

Directories

Path Synopsis
Package elements provides internal structures and functions for working with low-level document elements in GoDocx.
Package elements provides internal structures and functions for working with low-level document elements in GoDocx.

Jump to

Keyboard shortcuts

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