mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-06 08:10:25 +08:00
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
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
|
|
}
|