-
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.
* fix validate-example.sh * rename ci title * add ci build-examples.sh * update ci.yml path * update path for run main.go * update path * update examples * update validate-examples.sh * update * update usage-logs docx * add go mod tidy * remove node-remove example * remove document comment example * remove mutiple chart from csv * remove line chart from csv example * remove comment-remove example * remove comment-list example * remove copy reorder slide * fix examples * add variable for commentId on comment-remove example * add presentation use template sales example
- Loading branch information
Showing
18 changed files
with
190 additions
and
54 deletions.
There are no files selected for viewing
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,16 @@ | ||
#!/bin/bash | ||
|
||
cd $PWD | ||
go get github.com/go-ole/go-ole/oleutil@v1.3.0 | ||
go mod tidy | ||
|
||
:> build_errors | ||
find $PWD -maxdepth 2 -mindepth 1 -not -path '*/\.*' -type d -exec sh -c "cd {}; echo building {}; go build -tags=test main.go" 2>>build_log \; | ||
grep -v "^go: " build_log | grep -v main.go > build_errors | ||
if [[ $(wc -l build_errors | awk '{print $1}') == "0" ]]; then | ||
exit 0 | ||
fi | ||
echo BUILD ERRORS: | ||
cat build_errors | ||
echo END OF BUILD ERRORS. | ||
exit 1 |
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
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
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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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,157 @@ | ||
// Copyright 2025 FoxyUtils ehf. All rights reserved. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"encoding/json" | ||
|
||
"github.com/unidoc/unioffice/v2/common/license" | ||
"github.com/unidoc/unioffice/v2/schema/soo/pml" | ||
|
||
"github.com/unidoc/unioffice/v2/presentation" | ||
) | ||
|
||
type SaleInfo struct { | ||
Area string | ||
Sale string | ||
Customers int | ||
Manager string | ||
} | ||
|
||
type Data struct { | ||
Year int | ||
ID string | ||
SaleData []SaleInfo | ||
} | ||
|
||
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() { | ||
jsonData := []byte(` | ||
{ | ||
"year":2020, | ||
"id":"JI23SA", | ||
"SaleData":[ | ||
{ | ||
"area": "Michigan", | ||
"sale": "10 million", | ||
"customers": 10000, | ||
"manager": "Henry" | ||
}, | ||
{ | ||
"area": "Cincinnati", | ||
"sale": "2 million", | ||
"customers": 490, | ||
"manager": "John Green" | ||
}, | ||
{ | ||
"area": "Washington", | ||
"sale": "150 million", | ||
"customers": 100000, | ||
"manager": "Smith Johnson" | ||
} | ||
] | ||
} | ||
`) | ||
|
||
ppt, err := presentation.OpenTemplate("template.pptx") | ||
if err != nil { | ||
log.Fatalf("unable to open template: %s", err) | ||
} | ||
defer ppt.Close() | ||
|
||
for i, layout := range ppt.SlideLayouts() { | ||
fmt.Println(i, " LL ", layout.Name(), "/", layout.Type()) | ||
} | ||
|
||
var res Data | ||
err = json.Unmarshal(jsonData, &res) | ||
if err != nil { | ||
log.Fatalf("error unmarshalling JSON: %s", err) | ||
} | ||
saleData := res.SaleData | ||
|
||
for _, data := range saleData { // Iterate through the sale data | ||
// Remove any existing slides | ||
for _, s := range ppt.Slides() { | ||
err := ppt.RemoveSlide(s) | ||
if err != nil { | ||
log.Fatalf("error removing slide: %s", err) | ||
} | ||
} | ||
|
||
l, err := ppt.GetLayoutByName("Title and Caption") | ||
if err != nil { | ||
log.Fatalf("error retrieving layout: %s", err) | ||
} | ||
|
||
sld, err := ppt.AddDefaultSlideWithLayout(l) | ||
if err != nil { | ||
log.Fatalf("error adding slide: %s", err) | ||
} | ||
|
||
ph, err := sld.GetPlaceholder(pml.ST_PlaceholderTypeTitle) | ||
if err != nil { | ||
log.Fatalf("error getting placeholder type title: %s", err) | ||
} | ||
|
||
ph.SetText(fmt.Sprintf("Sale Data For: %s", data.Area)) | ||
|
||
ph, err = sld.GetPlaceholder(pml.ST_PlaceholderTypeBody) | ||
if err != nil { | ||
log.Fatalf("error getting placeholder type body: %s", err) | ||
} | ||
|
||
ph.SetText("Created with github.com/unidoc/unioffice/") | ||
|
||
tac, err := ppt.GetLayoutByName("Title and Content") | ||
if err != nil { | ||
log.Fatalf("error retrieving layout: %s", err) | ||
} | ||
|
||
sld, err = ppt.AddDefaultSlideWithLayout(tac) | ||
if err != nil { | ||
log.Fatalf("error adding slide: %s", err) | ||
} | ||
|
||
ph, err = sld.GetPlaceholder(pml.ST_PlaceholderTypeTitle) | ||
if err != nil { | ||
log.Fatalf("error getting placeholder type title: %s", err) | ||
} | ||
|
||
ph.SetText(fmt.Sprintf("Data for %s, Managed by %s", data.Area, data.Manager)) | ||
|
||
ph, err = sld.GetPlaceholderByIndex(1) | ||
if err != nil { | ||
log.Fatalf("error getting placeholder by index: %s", err) | ||
} | ||
|
||
ph.ClearAll() | ||
|
||
para := ph.AddParagraph() | ||
run := para.AddRun() | ||
run.SetText(fmt.Sprintf("Here is the number of sales in %s: $%s", data.Area, data.Sale)) | ||
|
||
para = ph.AddParagraph() | ||
run = para.AddRun() | ||
run.SetText(fmt.Sprintf("Number of Customers: %d", data.Customers)) | ||
|
||
para = ph.AddParagraph() | ||
run = para.AddRun() | ||
run.SetText(fmt.Sprintf("Manager: %s", data.Manager)) | ||
|
||
if err := ppt.SaveToFile(fmt.Sprintf("%s.pptx", data.Area)); err != nil { | ||
log.Fatalf("error saving presentation: %s", err) | ||
} | ||
} | ||
} |
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
Binary file not shown.
Binary file not shown.