Documentation
¶
Index ¶
Constants ¶
const ( TEMP_REL = `` /* 601-byte string literal not displayed */ TEMP_DOCPROPS_APP = `` /* 276-byte string literal not displayed */ TEMP_DOCPROPS_CORE = `` /* 363-byte string literal not displayed */ TEMP_CONTENT = `` /* 934-byte string literal not displayed */ TEMP_WORD_STYLE = `` /* 1743-byte string literal not displayed */ TEMP_WORD_THEME_THEME = `` /* 9767-byte string literal not displayed */ )
const ( XMLNS_W = `http://schemas.openxmlformats.org/wordprocessingml/2006/main` XMLNS_R = `http://schemas.openxmlformats.org/officeDocument/2006/relationships` )
const ( XMLNS = `http://schemas.openxmlformats.org/package/2006/relationships` REL_HYPERLINK = `http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink` REL_TARGETMODE = "External" )
const (
HYPERLINK_STYLE = "a1"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main color"`
Val string `xml:"w:val,attr"`
}
Color contains the sound of music. :D I'm kidding. It contains the color
type DocxLib ¶
type DocxLib struct {
Document Document
DocRelation Relationships
// contains filtered or unexported fields
}
DocxLib is the structure that allow to access the internal represntation in memory of the doc (either read or about to be written)
func New ¶
func New() *DocxLib
New generates a new empty docx file that we can manipulate and later on, save
func Parse ¶
Parse generates a new docx file in memory from a reader You can it invoke from a file
readFile, err := os.Open(FILE_PATH)
if err != nil {
panic(err)
}
fileinfo, err := readFile.Stat()
if err != nil {
panic(err)
}
size := fileinfo.Size()
doc, err := docxlib.Parse(readFile, int64(size))
but also you can invoke from a webform (BEWARE of trusting users data!!!)
func uploadFile(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(10 << 20)
file, handler, err := r.FormFile("file")
if err != nil {
fmt.Println("Error Retrieving the File")
fmt.Println(err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
defer file.Close()
docxlib.Parse(file, handler.Size)
}
func (*DocxLib) AddParagraph ¶
AddParagraph adds a new paragraph
func (*DocxLib) Paragraphs ¶
func (*DocxLib) References ¶
References gets the url for a reference
type Hyperlink ¶
type Hyperlink struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main hyperlink,omitempty"`
ID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr"`
Run Run
}
The hyperlink element contains links
func (*Hyperlink) UnmarshalXML ¶
type Paragraph ¶
type Paragraph struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main p"`
Data []ParagraphChild
// contains filtered or unexported fields
}
func (*Paragraph) Children ¶
func (p *Paragraph) Children() (ret []ParagraphChild)
func (*Paragraph) UnmarshalXML ¶
type ParagraphChild ¶
type ParagraphChild struct {
Link *Hyperlink `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main hyperlink,omitempty"`
Run *Run `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main r,omitempty"`
Properties *RunProperties `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPr,omitempty"`
}
type Relationship ¶
type Relationships ¶
type Relationships struct {
XMLName xml.Name `xml:"Relationships"`
Xmlns string `xml:"xmlns,attr"`
Relationships []*Relationship `xml:"Relationship"`
}
type Run ¶
type Run struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main r,omitempty"`
RunProperties *RunProperties `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPr,omitempty"`
InstrText string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main instrText,omitempty"`
Text *Text
}
A Run is part of a paragraph that has its own style. It could be a piece of text in bold, or a link
func (*Run) UnmarshalXML ¶
type RunProperties ¶
type RunProperties struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPr,omitempty"`
Color *Color `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main color,omitempty"`
Size *Size `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main sz,omitempty"`
RunStyle *RunStyle `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rStyle,omitempty"`
Style *Style `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main pStyle,omitempty"`
}
RunProperties encapsulates visual properties of a run
type RunStyle ¶
type RunStyle struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rStyle,omitempty"`
Val string `xml:"w:val,attr"`
}
RunStyle contains styling for a run
func (*RunStyle) UnmarshalXML ¶
type Size ¶
type Size struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main sz"`
Val int `xml:"w:val,attr"`
}
Size contains the font size
type Style ¶
type Style struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main pStyle,omitempty"`
Val string `xml:"w:val,attr"`
}
Style contains styling for a paragraph