Documentation
¶
Index ¶
- Constants
- type Body
- type DefinedStyle
- type Document
- type DocumentDefault
- type DocumentStyle
- type DocxFile
- type Fonts
- type Hyperlink
- type Indent
- type IntValueNode
- type LatentStyles
- type LsdException
- type PPrDefault
- type Paragraph
- func (p *Paragraph) AddLink(text string, link string) *Hyperlink
- func (p *Paragraph) AddText(text string) *Run
- func (p *Paragraph) GetOutlineLevel() int
- func (p *Paragraph) GetStyle() *DefinedStyle
- func (p *Paragraph) Text() string
- func (p *Paragraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type ParagraphProperties
- type RPrDefault
- type Relationship
- type Relationships
- type Run
- type RunProperties
- type Spacing
- type StrValueNode
- type TblCellMar
- type TblPr
- type Text
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 DefinedStyle ¶
type DefinedStyle struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main style"`
Type string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main type,attr"`
StyleId string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main styleId,attr"`
Name *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main name"`
BasedOn *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main basedOn"`
Next *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main next"`
Link string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main link"`
RPr *RunProperties `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPr"`
PPr *ParagraphProperties `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main pPr"`
AutoRedefine *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main autoRedefine"`
SemiHidden *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main semiHidden"`
QFormat *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main qFormat"`
UiPriority *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main uiPriority"`
TblPr *TblPr `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main tblPr"`
}
func (*DefinedStyle) GetName ¶
func (d *DefinedStyle) GetName() string
func (*DefinedStyle) HeadingLevel ¶
func (d *DefinedStyle) HeadingLevel() int
type Document ¶
type Document struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main document"`
XMLW string `xml:"xmlns:w,attr"`
XMLR string `xml:"xmlns:r,attr"`
Body *Body `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main body"`
Styles *DocumentStyle `xml:"-"`
}
type DocumentDefault ¶
type DocumentDefault struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main docDefaults"`
RPrDefault *RPrDefault `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPrDefault"`
PPrDefault *PPrDefault `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main pPrDefault"`
}
type DocumentStyle ¶
type DocumentStyle struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main styles"`
XMLW string `xml:"xmlns:w,attr"`
XMLR string `xml:"xmlns:r,attr"`
DocumentDefault *DocumentDefault `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main docDefaults"`
LatentStyles *LatentStyles `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main latentStyles"`
Styles []*DefinedStyle `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main style"`
// contains filtered or unexported fields
}
func (*DocumentStyle) GetStyleById ¶
func (d *DocumentStyle) GetStyleById(styleId string) *DefinedStyle
type DocxFile ¶
type DocxFile struct {
Document Document
DocRelation Relationships
// contains filtered or unexported fields
}
DocxFile 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() *DocxFile
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 := docx.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()
docx.Parse(file, handler.Size)
}
func (*DocxFile) AddParagraph ¶
AddParagraph adds a new paragraph
func (*DocxFile) GetStyleById ¶
func (d *DocxFile) GetStyleById(styleId string) *DefinedStyle
func (*DocxFile) Paragraphs ¶
func (*DocxFile) References ¶
References gets the url for a reference
type Fonts ¶
type Fonts struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rFonts,omitempty"`
Ascii string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main ascii,attr"`
HAnsi string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main hAnsi,attr"`
EastAsia string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main eastAsia,attr"`
Complex string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main complex,attr"`
Cs string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main cs,attr"`
}
Fonts contains the font family
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 `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main r,omitempty"`
// contains filtered or unexported fields
}
The hyperlink element contains links
type Indent ¶
type Indent struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main ind,omitempty"`
First int `xml:"http://schemas.openxmlformats.org/2006/main first,attr"`
Hanging int `xml:"http://schemas.openxmlformats.org/2006/main hanging,attr"`
Left int `xml:"http://schemas.openxmlformats.org/2006/main left,attr"`
Right int `xml:"http://schemas.openxmlformats.org/2006/main right,attr"`
LeftChars int `xml:"http://schemas.openxmlformats.org/2006/main leftChars,attr"`
RightChars int `xml:"http://schemas.openxmlformats.org/2006/main rightChars,attr"`
}
type IntValueNode ¶
type LatentStyles ¶
type LatentStyles struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main latentStyles"`
LsdExceptions []*LsdException `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main lsdException"`
Count int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main count,attr"`
DefQFormat int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main defQFormat,attr"`
DefUnhideWhenUsed int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main defUnhideWhenUsed,attr"`
DefUIPriority int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main defUIPriority,attr"`
DefLockedState int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main defLockedState,attr"`
DefSemiHidden int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main defSemiHidden,attr"`
DefPrimaryStyle int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main defPrimaryStyle,attr"`
}
type LsdException ¶
type LsdException struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main lsdException"`
Name string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main name,attr"`
Locked int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main locked,attr"`
SemiHidden int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main semiHidden,attr"`
UnhideWhenUsed int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main unhideWhenUsed,attr"`
QFormat int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main qFormat,attr"`
UIPriority int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main uiPriority,attr"`
PrimaryStyle int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main primaryStyle,attr"`
}
type PPrDefault ¶
type PPrDefault struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main pPrDefault"`
PPr *ParagraphProperties `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main pPr"`
}
type Paragraph ¶
type Paragraph struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main p"`
Properties *ParagraphProperties
Links []*Hyperlink `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main hyperlink,omitempty"`
Runs []*Run `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main r,omitempty"`
// contains filtered or unexported fields
}
func (*Paragraph) GetOutlineLevel ¶
func (*Paragraph) GetStyle ¶
func (p *Paragraph) GetStyle() *DefinedStyle
func (*Paragraph) UnmarshalXML ¶
type ParagraphProperties ¶
type ParagraphProperties struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main pPr"`
Style *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main pStyle,omitempty"`
Spacing *Spacing `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main spacing,omitempty"`
Ind *Indent `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main ind,omitempty"`
Jc *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main jc,omitempty"`
Outline *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main outlineLvl,omitempty"`
}
func (*ParagraphProperties) GetStyleId ¶
func (p *ParagraphProperties) GetStyleId() string
type RPrDefault ¶
type RPrDefault struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPrDefault"`
RPr *RunProperties `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPr"`
}
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
// contains filtered or unexported fields
}
A Run is part of a paragraph that has its own style. It could be a piece of text in bold, or a link
type RunProperties ¶
type RunProperties struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPr,omitempty"`
Color *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main color,omitempty"`
Size *IntValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main sz,omitempty"`
RunStyle *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rStyle,omitempty"`
Style *StrValueNode `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main pStyle,omitempty"`
Fonts *Fonts `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rFonts,omitempty"`
}
RunProperties encapsulates visual properties of a run
type Spacing ¶
type Spacing struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main spacing,omitempty"`
After int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main after,attr"`
Before int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main before,attr"`
Line int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main line,attr"`
}
type StrValueNode ¶
type StrValueNode struct {
XMLName xml.Name
Val string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main val,attr"`
}
func (*StrValueNode) String ¶
func (v *StrValueNode) String() string
type TblCellMar ¶
type TblCellMar struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main tblCellMar"`
Top int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main top,attr"`
Left int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main left,attr"`
Bottom int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main bottom,attr"`
Right int `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main right,attr"`
}
type TblPr ¶
type TblPr struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main tblPr"`
TblStyle string `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main tblStyle,attr"`
TblCellMar *TblCellMar `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main tblCellMar"`
}