-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.