mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-25 13:48:53 +08:00
93 lines
2.3 KiB
Go
93 lines
2.3 KiB
Go
// Copyright 2017 Baliance. All rights reserved.
|
|
package main
|
|
|
|
import (
|
|
"baliance.com/gooxml/color"
|
|
"baliance.com/gooxml/document"
|
|
"baliance.com/gooxml/measurement"
|
|
"baliance.com/gooxml/schema/soo/wml"
|
|
)
|
|
|
|
func main() {
|
|
doc := document.New()
|
|
|
|
para := doc.AddParagraph()
|
|
run := para.AddRun()
|
|
para.SetStyle("Title")
|
|
run.AddText("Simple Document Formatting")
|
|
|
|
para = doc.AddParagraph()
|
|
para.SetStyle("Heading1")
|
|
run = para.AddRun()
|
|
run.AddText("Some Heading Text")
|
|
|
|
para = doc.AddParagraph()
|
|
para.SetStyle("Heading2")
|
|
run = para.AddRun()
|
|
run.AddText("Some Heading Text")
|
|
|
|
para = doc.AddParagraph()
|
|
para.SetStyle("Heading3")
|
|
run = para.AddRun()
|
|
run.AddText("Some Heading Text")
|
|
|
|
para = doc.AddParagraph()
|
|
para.Properties().SetFirstLineIndent(0.5 * measurement.Inch)
|
|
|
|
run = para.AddRun()
|
|
run.AddText("A run is a string of characters with the same formatting. ")
|
|
|
|
run = para.AddRun()
|
|
run.Properties().SetBold(true)
|
|
run.Properties().SetFontFamily("Courier")
|
|
run.Properties().SetSize(15)
|
|
run.Properties().SetColor(color.Red)
|
|
run.AddText("Multiple runs with different formatting can exist in the same paragraph. ")
|
|
|
|
run = para.AddRun()
|
|
run.AddText("Adding breaks to a run will insert line breaks after the run. ")
|
|
run.AddBreak()
|
|
run.AddBreak()
|
|
|
|
run = createParaRun(doc, "Runs support styling options:")
|
|
|
|
run = createParaRun(doc, "small caps")
|
|
run.Properties().SetSmallCaps(true)
|
|
|
|
run = createParaRun(doc, "strike")
|
|
run.Properties().SetStrikeThrough(true)
|
|
|
|
run = createParaRun(doc, "double strike")
|
|
run.Properties().SetDoubleStrikeThrough(true)
|
|
|
|
run = createParaRun(doc, "outline")
|
|
run.Properties().SetOutline(true)
|
|
|
|
run = createParaRun(doc, "emboss")
|
|
run.Properties().SetEmboss(true)
|
|
|
|
run = createParaRun(doc, "shadow")
|
|
run.Properties().SetShadow(true)
|
|
|
|
run = createParaRun(doc, "imprint")
|
|
run.Properties().SetImprint(true)
|
|
|
|
run = createParaRun(doc, "highlighting")
|
|
run.Properties().SetHighlight(wml.ST_HighlightColorYellow)
|
|
|
|
run = createParaRun(doc, "underline")
|
|
run.Properties().SetUnderline(wml.ST_UnderlineWavyDouble, color.Red)
|
|
|
|
run = createParaRun(doc, "text effects")
|
|
run.Properties().SetEffect(wml.ST_TextEffectAntsRed)
|
|
|
|
doc.SaveToFile("simple.docx")
|
|
}
|
|
|
|
func createParaRun(doc *document.Document, s string) document.Run {
|
|
para := doc.AddParagraph()
|
|
run := para.AddRun()
|
|
run.AddText(s)
|
|
return run
|
|
}
|