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

feat: Docx implements io.WriterTo

This commit is contained in:
源文雨
2023-02-09 15:22:47 +08:00
parent f995e72acd
commit 56810d8288
5 changed files with 62 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
package docxlib
import "strings"
// AddText adds text to paragraph
func (p *Paragraph) AddText(text string) *Run {
t := &Text{
@@ -15,3 +17,30 @@ func (p *Paragraph) AddText(text string) *Run {
return run
}
func (p *Paragraph) String() string {
sb := strings.Builder{}
for _, c := range p.Children {
switch {
case c.Link != nil:
id := c.Link.ID
text := c.Link.Run.InstrText
link, err := p.file.Refer(id)
sb.WriteString(text)
sb.WriteByte('(')
if err != nil {
sb.WriteString(id)
} else {
sb.WriteString(link)
}
sb.WriteByte(')')
case c.Run != nil:
sb.WriteString("run") //TODO: implement
case c.Properties != nil:
sb.WriteString("prop") //TODO: implement
default:
continue
}
}
return sb.String()
}