Skip to content

Commit

Permalink
prepare v1.19.0 examples (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnsth committed Apr 9, 2022
1 parent 52c0110 commit 4a3b185
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 4 deletions.
Binary file not shown.
106 changes: 106 additions & 0 deletions document/bullet-and-numbering/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2022 UniDoc ehf. All rights reserved.
package main

import (
"fmt"
"os"

"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/document"
"github.com/unidoc/unioffice/measurement"
"github.com/unidoc/unioffice/schema/soo/wml"
)

func init() {
// Make sure to load your metered License API key prior to using the library.
// If you need a key, you can sign up and create a free one at https://cloud.unidoc.io
err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
if err != nil {
panic(err)
}
}

var mapList = []map[string][]string{
map[string][]string{"Preferred programming language": []string{"Go", "Java", "PHP"}},
map[string][]string{"Which sport you love to play": []string{"Football", "Basketball", "Diving"}},
map[string][]string{"Another information": []string{"This A", "This B", "This C"}},
}

func main() {
doc := document.New()
defer doc.Close()

// Create numbering definition.
nd := doc.Numbering.AddDefinition()

// Add level to number definition with decimal format.
lvl := nd.AddLevel()
lvl.SetFormat(wml.ST_NumberFormatDecimal)
lvl.SetAlignment(wml.ST_JcLeft)
lvl.Properties().SetLeftIndent(0.5 * measurement.Distance(1) * measurement.Inch)

// Sets the numbering level format.
lvl.SetText("%1.")

for i := 0; i < len(mapList); i++ {
for key, val := range mapList[i] {
para := doc.AddParagraph()
para.SetNumberingDefinition(nd)
para.SetNumberingLevel(0)
para.AddRun().AddText(key)

// Create children numbering definition.
ndChildren := doc.Numbering.AddDefinition()

// Add level to number definition with lower roman format.
lvl := ndChildren.AddLevel()
lvl.SetFormat(wml.ST_NumberFormatLowerRoman)
lvl.SetAlignment(wml.ST_JcLeft)
lvl.Properties().SetLeftIndent(0.5 * measurement.Distance(2) * measurement.Inch)

// Sets the numbering level format.
lvl.SetText("%1.")

for i := 0; i < len(val); i++ {
para := doc.AddParagraph()
para.SetNumberingDefinition(ndChildren)
para.SetNumberingLevel(0)
para.AddRun().AddText(val[i])

// Add more nested numbering.
if i == 0 && key == "Another information" {
// Create children numbering definition.
ndChild := doc.Numbering.AddDefinition()

// Add level to number definition with upper letter format.
lvl := ndChild.AddLevel()
lvl.SetFormat(wml.ST_NumberFormatUpperLetter)
lvl.SetAlignment(wml.ST_JcLeft)
lvl.Properties().SetLeftIndent(0.5 * measurement.Distance(3) * measurement.Inch)

// Sets the numbering level format.
lvl.SetText("%1.)")
for i := 1; i < 5; i++ {
p := doc.AddParagraph()
p.SetNumberingLevel(0)
p.SetNumberingDefinition(ndChild)
run := p.AddRun()
run.AddText(fmt.Sprintf("More Level %d", i))
}
}
}
}
}

// Numbering bullet.
ndBullet := doc.Numbering.Definitions()[0]
for i := 1; i < 5; i++ {
p := doc.AddParagraph()
p.SetNumberingLevel(i - 1)
p.SetNumberingDefinition(ndBullet)
run := p.AddRun()
run.AddText(fmt.Sprintf("Level %d", i))
}

doc.SaveToFile("bullet-and-numbering.docx")
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/unidoc/unioffice-examples

go 1.13
go 1.14

require (
github.com/go-ole/go-ole v1.2.6
github.com/unidoc/unioffice v1.17.0
github.com/unidoc/unioffice v1.19.0
github.com/unidoc/unipdf/v3 v3.31.0
golang.org/x/sys v0.0.0-20211109065445-02f5c0300f6e // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/unidoc/pkcs7 v0.1.0 h1:9bQfbWMYsIfUP8PyhTcBudOsvbLpNH0MBv4U0P/jDTE=
github.com/unidoc/pkcs7 v0.1.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8=
github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc=
github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw=
github.com/unidoc/unioffice v1.17.0 h1:B65bz1LEbK6N49BOjfrDiG5tbreZLvpWprd8mfCc3WE=
github.com/unidoc/unioffice v1.17.0/go.mod h1:q+c+7USR3+8hBhK7+XgGq6OO3yUHUv2EXTP8DfF4gcY=
github.com/unidoc/unioffice v1.19.0 h1:dgXZVexCp13C+AG51b6cgKzQse8u5AkEFuOFFThas8k=
github.com/unidoc/unioffice v1.19.0/go.mod h1:q+c+7USR3+8hBhK7+XgGq6OO3yUHUv2EXTP8DfF4gcY=
github.com/unidoc/unipdf/v3 v3.31.0 h1:cDjCgV2eUuuCatFauzC+kt39VoAvYzOy+QfgZafVOyY=
github.com/unidoc/unipdf/v3 v3.31.0/go.mod h1:Lf6mZ1+s/7mzFI1+gXFRae3qZgGg3LEAeZJhbUx3+80=
github.com/unidoc/unitype v0.2.1 h1:x0jMn7pB/tNrjEVjy3Ukpxo++HOBQaTCXcTYFA6BH3w=
Expand Down
59 changes: 59 additions & 0 deletions presentation/slide-size/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2022 UniDoc ehf. All rights reserved.
package main

import (
"log"
"os"

"github.com/unidoc/unioffice/color"
"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/measurement"
"github.com/unidoc/unioffice/presentation"
"github.com/unidoc/unioffice/schema/soo/dml"
)

func init() {
// Make sure to load your metered License API key prior to using the library.
// If you need a key, you can sign up and create a free one at https://cloud.unidoc.io
err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
if err != nil {
panic(err)
}
}

func main() {
ppt := presentation.New()
defer ppt.Close()

for i := 0; i < 5; i++ {
slide := ppt.AddSlide()

tb := slide.AddTextBox()
tb.Properties().SetGeometry(dml.ST_ShapeTypeStar10)

tb.Properties().SetWidth(3 * measurement.Inch)
pos := measurement.Distance(i) * measurement.Inch
tb.Properties().SetPosition(pos, pos)

tb.Properties().SetSolidFill(color.AliceBlue)
tb.Properties().LineProperties().SetSolidFill(color.Blue)

p := tb.AddParagraph()
p.Properties().SetAlign(dml.ST_TextAlignTypeCtr)

r := p.AddRun()
r.SetText("gooxml")
r.Properties().SetSize(24 * measurement.Point)
}

// SlideSize returns the presentation slide size,
// using SlideSize, we can sets the slide size.
// Example below sets the slide size width: 13.33" and height: 7.50" (wide 16x9).
slideSize := ppt.SlideSize()
slideSize.SetSize(presentation.SlideScreenSize16x9)

if err := ppt.Validate(); err != nil {
log.Fatal(err)
}
ppt.SaveToFile("slide-size.pptx")
}
Binary file added presentation/slide-size/slide-size.pptx
Binary file not shown.

0 comments on commit 4a3b185

Please sign in to comment.