1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-10 10:23:19 +08:00

First commit

This commit is contained in:
Gonzalo Fernandez-Victorio
2021-04-23 16:58:31 +01:00
parent bd1f5d3e9b
commit eae5f90385
16 changed files with 957 additions and 0 deletions

42
paragraph.go Normal file
View File

@@ -0,0 +1,42 @@
package docxlib
import (
"encoding/xml"
)
type ParagraphChild struct {
Link *Hyperlink `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main hyperlink"`
Run *Run `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main r"`
}
type Paragraph struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main p"`
Data []ParagraphChild
file *Docx
}
// AddParagraph adds a new paragraph
func (f *Docx) AddParagraph() *Paragraph {
p := &Paragraph{
Data: make([]ParagraphChild, 0),
file: f,
}
f.Document.Body.Paragraphs = append(f.Document.Body.Paragraphs, p)
return p
}
func (f *Docx) Paragraphs() []*Paragraph {
return f.Document.Body.Paragraphs
}
func (p *Paragraph) Runs() (ret []*Run) {
data := p.Data
for _, d := range data {
if d.Run != nil {
ret = append(ret, d.Run)
}
}
return
}