mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-15 22:10:26 +08:00
First commit
This commit is contained in:
58
run.go
Normal file
58
run.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package docxlib
|
||||
|
||||
import "encoding/xml"
|
||||
|
||||
// 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 Run struct {
|
||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main r"`
|
||||
RunProperties *RunProperties `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPr,omitempty"`
|
||||
InstrText string `xml:"w:instrText,omitempty"`
|
||||
Text *Text
|
||||
}
|
||||
|
||||
// The Text object contains the actual text
|
||||
type Text struct {
|
||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main t"`
|
||||
XMLSpace string `xml:"xml:space,attr,omitempty"`
|
||||
Text string `xml:",chardata"`
|
||||
}
|
||||
|
||||
type Hyperlink struct {
|
||||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main hyperlink"`
|
||||
ID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr"`
|
||||
Run Run
|
||||
}
|
||||
|
||||
// Color allows to set run color
|
||||
func (r *Run) Color(color string) *Run {
|
||||
r.RunProperties.Color = &Color{
|
||||
Val: color,
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// Size allows to set run size
|
||||
func (r *Run) Size(size int) *Run {
|
||||
r.RunProperties.Size = &Size{
|
||||
Val: size * 2,
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// AddText add text to paragraph
|
||||
func (p *Paragraph) AddText(text string) *Run {
|
||||
t := &Text{
|
||||
Text: text,
|
||||
}
|
||||
|
||||
run := &Run{
|
||||
Text: t,
|
||||
RunProperties: &RunProperties{},
|
||||
}
|
||||
|
||||
p.Data = append(p.Data, ParagraphChild{Run: run})
|
||||
|
||||
return run
|
||||
}
|
||||
Reference in New Issue
Block a user