Skip to content

Commit

Permalink
Sync with development (#55)
Browse files Browse the repository at this point in the history
* update readme.md, add ci validate examples

* Fix validate examples (#54)

* 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
sampila authored Feb 14, 2025
1 parent 9ed633f commit 74818d7
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 67 deletions.
16 changes: 16 additions & 0 deletions .ci/build-examples.sh
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
10 changes: 10 additions & 0 deletions .ci/dotnet_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
output=$(dotnet ./openxml-validator/bin/Release/net8.0/Program.dll --$2 $1)
echo $output
echo ""
if [[ $output == *"is not valid"* ]]; then
if [[ $output != *"main:sz"* ]] && [[ $output != *"main:family"* ]] && [[ $output != *"chart:ext"* ]] ; then
echo $output >> errors
echo "" >> errors
fi
fi
6 changes: 6 additions & 0 deletions .ci/skip_files
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
values.xlsx
chart.pptx
lists.pptx
picture.pptx
several_slides.pptx
table.pptx
19 changes: 19 additions & 0 deletions .ci/validate-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
:> errors
output=$(find .. -maxdepth 2 -mindepth 2 -not -path '*/\.*' -type d ! -name "metered" ! -name "offline" ! -name "metered-non-persistent-cache" ! -name "usage-logs" -print0 | xargs -0 -I{} sh -c "cd {}; echo running {}; ./main")
if [ $? -ne 0 ]; then
echo $output >> errors
fi
export PATH=$PATH:$HOME/dotnet
find .. -name "*.docx" $(printf "! -name %s " $(cat skip_files)) -exec ./dotnet_run.sh {} docx \;
find .. -name "*.xlsx" $(printf "! -name %s " $(cat skip_files)) -exec ./dotnet_run.sh {} xlsx \;
find .. -name "*.pptx" $(printf "! -name %s " $(cat skip_files)) -exec ./dotnet_run.sh {} pptx \;
echo Errors: $(wc -l errors)
if [[ $(wc -l errors | awk '{print $1}') == "0" ]]; then
exit 0
fi

echo "Validation errors"
cat errors
echo "EOF Validation errors"
exit 1
Binary file added .ci/validator.zip
Binary file not shown.
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: UniOffice Examples CI

on:
push:
branches: [ master, development ]
pull_request:
branches: [ master, development ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
go-version: [ '1.23', '1.22', '1.21', '1.20', '1.19' ]

env:
CGO_ENABLED: 0
GITHUB_REF: ${{ github.ref }}
UNIDOC_LICENSE_API_KEY: ${{ secrets.UNIDOC_LICENSE_API_KEY }}

steps:
- uses: actions/checkout@v3

- name: Use Golang ${{ matrix.go-version }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Fetch dotnet
run: |
mkdir -p $HOME/dotnet
cd $HOME/dotnet
wget https://download.visualstudio.microsoft.com/download/pr/4e3b04aa-c015-4e06-a42e-05f9f3c54ed2/74d1bb68e330eea13ecfc47f7cf9aeb7/dotnet-sdk-8.0.404-linux-x64.tar.gz
tar -xf dotnet-sdk-8.0.404-linux-x64.tar.gz
- name: Test and validate examples
run: |
export REPO=$PWD
cd $REPO/.ci
ls -la
unzip validator.zip
ls -la
cd $REPO/.ci/openxml-validator
$HOME/dotnet/dotnet build --configuration Release
cd $REPO
./.ci/build-examples.sh
cd $REPO/.ci
./validate-examples.sh
if [ $? -ne 0 ]
then exit 1
fi
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ Anyone can get a free metered API key by signing up on http://cloud.unidoc.io/
- [license/metered/main.go](license/metered/main.go) Demonstrates how to load the Metered API license key and how to print out relevant information.
- [license/metered-non-persistent-cache/main.go](license/metered-non-persistent-cache/main.go) Demonstrates how to load the Metered API license key for instances that not having persistent storage for usages cache and print out relevant information. When working with short-lived containers like docker or kubernetes instances usually it's doesn't have persistent storage location and will be destroyed after being idle.
- [license/offline/main.go](license/offline/main.go) Demonstrates how to print out information about the license after loading an offline license key.
- [license/usage-logs/main.go](license/usage-logs/main.go) This example shows how to display license usage logs for read and editing simple docx file.

### Metered License Key Usage Logs
When using unioffice on metered api key it is possible to see the usage logs of license key in every run. To enable this set the `license.SetMeteredKeyUsageLogVerboseMode` to `true` and to print out into console set the `logger.SetLogger` to Info or higher. as follows. This is available for metered api key only.

```go
// Set the log level to info or higher
logger.SetLogger(logger.NewConsoleLogger(logger.LogLevelInfo))

// Enable the verbose mode logging
license.SetMeteredKeyUsageLogVerboseMode(true)
```
Sample output
```bash
[INFO] metered.go:674 2024-09-26 20:32:22.607531 +0300 +03 m=+0.412134293 | File grocery_list.docx | Ref: dr17f8db | document.Read | 1 credit(s) used
[INFO] metered.go:506 2024-09-26 20:32:22.653044 +0300 +03 m=+0.457648876 Ref: dr17f8db | document:d.Save | No credit used
```

### Build all examples

Expand Down
9 changes: 1 addition & 8 deletions document/comment-list/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@ func init() {
}

func main() {
if len(os.Args) < 2 {
fmt.Printf("Syntax: go run main.go input.docx\n")
os.Exit(1)
}

inputPath := os.Args[1]

doc, err := document.Open(inputPath)
doc, err := document.Open("sample.docx")
if err != nil {
log.Fatalf("error opening document: %s", err)
}
Expand Down
Binary file added document/comment-list/sample.docx
Binary file not shown.
19 changes: 4 additions & 15 deletions document/comment-remove/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"log"
"os"
"strconv"

"github.com/unidoc/unioffice/v2/common/license"
"github.com/unidoc/unioffice/v2/document"
Expand All @@ -26,28 +25,18 @@ func init() {
}

func main() {
if len(os.Args) < 3 {
fmt.Printf("Syntax: go run main.go input.docx comment_id\n")
os.Exit(1)
}

inputPath := os.Args[1]
commentId, err := strconv.Atoi(os.Args[2])
if err != nil {
log.Fatalf("error parsing comment id: %s", err)
}

doc, err := document.Open(inputPath)
doc, err := document.Open("sample.docx")
if err != nil {
log.Fatalf("error opening document: %s", err)
}
defer doc.Close()

listComments(doc)

if sucess := doc.RemoveComment(int64(commentId)); !sucess {
fmt.Println("Failed removing comment")
commentId := int64(2)

if ok := doc.RemoveComment(commentId); !ok {
fmt.Println("Failed removing comment")
return
}

Expand Down
Binary file added document/comment-remove/sample.docx
Binary file not shown.
14 changes: 2 additions & 12 deletions document/node-remove/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package main

import (
"fmt"
"log"
"os"

Expand All @@ -20,16 +19,7 @@ func init() {
}

func main() {
args := os.Args
if len(args) < 2 {
fmt.Printf("Usage %s go run main.go input.docx output.docx", os.Args[0])
return
}

inputPath := args[1]
outputPath := args[2]

doc, err := document.Open(inputPath)
doc, err := document.Open("sample.docx")
if err != nil {
log.Fatalf("error opening document: %s", err)
}
Expand All @@ -46,7 +36,7 @@ func main() {
}
}

err = doc.SaveToFile(outputPath)
err = doc.SaveToFile("output.docx")
if err != nil {
panic(err)
}
Expand Down
Binary file modified document/template-with-header/letter_template.docx
Binary file not shown.
Binary file added document/use-template/use-template.docx
Binary file not shown.
20 changes: 0 additions & 20 deletions license/usage-logs/README.md

This file was deleted.

Binary file modified license/usage-logs/grocery_list.docx
Binary file not shown.
Binary file modified license/usage-logs/updated_list.docx
Binary file not shown.
2 changes: 1 addition & 1 deletion presentation/copy-reorder-slide/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
}

// move inserted slide to the very beginning of presentation, it becomes slide 0
err = pptTo.MoveSlide(4, 0)
err = pptTo.MoveSlide(len(pptTo.Slides())-1, 1)
if err != nil {
fmt.Println("error moving slide ", err)
os.Exit(1)
Expand Down
Loading

0 comments on commit 74818d7

Please sign in to comment.