ooxml

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

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

Document represents a Microsoft Word document in the Office Open XML format. It maintains references to the main document XML, relationships, numbering definitions, headers, footers, images, and template tags.

For more details on the OOXML format, see: http://officeopenxml.com/anatomyofOOXML.php

func NewDocument

func NewDocument(template []byte) (*Document, error)

NewDocument creates a new Word document from a template.

The template parameter should contain the bytes of a valid .docx file. This function parses the OOXML structure, extracting the document content, relationships, numbering definitions, headers, and footers.

Returns a Document that can be modified using its methods, or an error if the template is invalid or required components are missing.

func (*Document) GetBookmark

func (doc *Document) GetBookmark(name string) *Element

GetBookmark finds and returns the bookmark element with the specified name.

Returns a pointer to an Element representing the bookmark location, or nil if the bookmark is not found or is not within the document body.

func (*Document) InsertHTML

func (doc *Document) InsertHTML(input io.Reader, bookmark string) error

InsertHTML inserts HTML content into the document at the specified bookmark location.

This method parses HTML from the input reader and converts it to corresponding OOXML elements, inserting them at the bookmark position. The bookmark must exist in the document.

Returns an error if the bookmark is not found or if there are issues parsing the HTML.

func (*Document) InsertMarkdown

func (doc *Document) InsertMarkdown(input io.Reader, bookmark string) error

InsertMarkdown converts Markdown content to HTML and inserts it into the document at the specified bookmark location.

This method uses goldmark to convert Markdown to HTML, then delegates to InsertHTML.

Returns an error if the bookmark is not found or if there are issues parsing the Markdown or inserting the HTML.

func (*Document) RenderTags

func (doc *Document) RenderTags(ctx any) error

RenderTags renders all template tags in the document using the provided context.

Template tags are text placeholders in the format {{tagName}} found throughout the document (body, headers, footers). Each tag is evaluated as a Go template expression using the provided context.

Returns an error if there are issues parsing or rendering any template tag.

func (*Document) Write

func (doc *Document) Write(w io.Writer) error

Write writes the document to the provided io.Writer. The output is a complete .docx file in OOXML format.

Returns an error if there are issues serializing or writing the document.

func (*Document) WriteFile

func (doc *Document) WriteFile(path string) error

WriteFile writes the document to a file at the specified path. The output is a complete .docx file that can be opened in Microsoft Word.

Returns an error if the file cannot be created or written.

type Element

type Element struct {
	// contains filtered or unexported fields
}

Element is an OOXML Element

func (*Element) AddChild

func (e *Element) AddChild(child *Element) *Element

AddChild adds a new child token and returns the child

func (*Element) AddXML

func (e *Element) AddXML(child *etree.Element) *Element

AddXML adds a new child XML element

func (*Element) Parent

func (e *Element) Parent() *Element

Parent returns the Parent token or nil

type PropSet

type PropSet struct {
	// contains filtered or unexported fields
}

PropSet defines a unique set of properties

func Props

func Props(props ...prop) *PropSet

Props is a shortcut to generate a PropSet from a list of properties

func (*PropSet) Add

func (set *PropSet) Add(v prop) *PropSet

Add adds a new property to a PropSet

func (*PropSet) Contains

func (set *PropSet) Contains(v prop) bool

Contains determines if a PropSet contains a given property

func (*PropSet) Difference

func (set *PropSet) Difference(other *PropSet) *PropSet

Difference determines set a - b

func (*PropSet) Empty

func (set *PropSet) Empty() bool

Empty return true if PropSet is empty

func (*PropSet) Equals

func (set *PropSet) Equals(other *PropSet) bool

Equals determines if set a = b

func (*PropSet) Iter

func (set *PropSet) Iter() []prop

Iter creates an iterable list from a PropSet

func (*PropSet) String

func (set *PropSet) String() string

func (*PropSet) Union

func (set *PropSet) Union(other *PropSet) *PropSet

Union creates a new PropSet combing two existing PropSets

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

Tag is a text templating tag

Example: {{tagName}}

Tags are used for simple text replacement in parts of the document where HTML templating is not required or lacks features, e.g. headers, footers, complex cover pages.

Jump to

Keyboard shortcuts

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