writer

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package writer handles writing DOCX files as ZIP archives containing XML documents. It provides the ZipWriter for creating properly structured Office Open XML packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NumberingPart

type NumberingPart struct {
	Data   []byte
	Target string
}

NumberingPart represents numbering.xml data that should be preserved in the DOCX package.

type PreservedParts added in v2.2.1

type PreservedParts struct {
	Headers          map[string][]byte // Original headers (e.g., "header1.xml" -> bytes)
	Footers          map[string][]byte // Original footers (e.g., "footer1.xml" -> bytes)
	DocRels          []byte            // Original word/_rels/document.xml.rels
	ContentTypes     []byte            // Original [Content_Types].xml
	Additional       map[string][]byte // Additional parts (comments, footnotes, customXml, etc.)
	Themes           map[string][]byte // Original theme parts
	FontTable        []byte            // Original fontTable.xml
	Settings         []byte            // Original settings.xml
	WebSettings      []byte            // Original webSettings.xml
	CustomProperties []byte            // Original docProps/custom.xml
	RootRels         []byte            // Original _rels/.rels
}

PreservedParts holds all parts that should be written verbatim from the original document. This enables complete round-trip fidelity when reading and saving documents.

type ZipWriter

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

ZipWriter writes a .docx file to an io.Writer.

func NewZipWriter

func NewZipWriter(w io.Writer) *ZipWriter

NewZipWriter creates a new ZipWriter.

func (*ZipWriter) Close

func (zw *ZipWriter) Close() error

Close closes the ZIP writer.

func (*ZipWriter) WriteDocument

func (zw *ZipWriter) WriteDocument(doc *xmlstructs.Document, rels *xmlstructs.Relationships, coreProps *xmlstructs.CoreProperties, appProps *xmlstructs.AppProperties, styles *xmlstructs.Styles, media []*manager.MediaFile, headers map[string]*xmlstructs.Header, footers map[string]*xmlstructs.Footer, numbering *NumberingPart, preservedStyles []byte, preserved *PreservedParts) error

WriteDocument writes a complete .docx document structure. If preservedStyles is provided (non-nil), it will be written verbatim instead of serializing styles. If preserved is provided, those parts will be written verbatim for complete round-trip fidelity.

Jump to

Keyboard shortcuts

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