4 Commits

Author SHA1 Message Date
d5a803644b do formatting to heading row of empty worksheet
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2024-06-28 09:19:25 +10:00
bfa2afbb6c add CICD
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2024-06-28 09:02:31 +10:00
24560ee8bf improve handling of empty data 2024-06-28 08:59:22 +10:00
2a89008a54 generate empty workbook if no data to add 2023-06-15 10:41:33 +10:00
3 changed files with 99 additions and 7 deletions

15
.drone.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
# disable CGO for cross-compiling
export CGO_ENABLED=0
export now=$(TZ=Australia/Sydney date '+%Y%m%d-%H%M%S')
echo $now
#pwd
#ls -lah ~
#go env
echo "build commences"
go build -ldflags "-X main.sha1ver=`git rev-parse HEAD` -X main.buildTime=$now" -o json2excel
echo "build complete"
sha256sum json2excel > json2excel_checksum.txt
ls -lah

30
.drone.yml Normal file
View File

@@ -0,0 +1,30 @@
kind: pipeline
type: docker
name: default
# Docs at https://docs.drone.io/pipeline/exec/overview/
# Also see https://github.com/harness/drone-cli/blob/master/.drone.yml
steps:
- name: build
image: golang
environment:
CGO_ENABLED: 0
commands:
- sh ./.drone.sh
- name: dell-sftp-deploy
image: hypervtechnics/drone-sftp
settings:
host: deft.dell.com
username:
from_secret: DELLFTP_USER
password:
from_secret: DELLFTP_PASS
port: 22
source: ./
filter: json2excel*
clean: false
target: /
overwrite: true
verbose: true

View File

@@ -153,6 +153,53 @@ func main() {
// Get an interface that we can work with to access the sub elements // Get an interface that we can work with to access the sub elements
vslice := vislice.([]interface{}) vslice := vislice.([]interface{})
if len(vslice) < 1 {
// There was no data but lets just log that and close off the empty workbook
fmt.Printf("No data found contained in top-level json key '%s', no work to do.\n", parentNode)
// Create new file
xlsx = createWorkbook(worksheetName, outputFilename)
// Run code to add column names to the first row of the workbook based off the keyOrder, if defined
if len(config.keyOrder) > 0 {
var columnHeadings []string
for _, value := range config.keyOrder {
columnHeadings = append(columnHeadings, value)
}
createHeadingRow(xlsx, worksheetName, columnHeadings)
headerStyle, err := xlsx.NewStyle(&excelize.Style{
Font: &excelize.Font{
Bold: true,
},
})
if err != nil {
fmt.Printf("Error generating header style : '%s'\n", err)
} else {
// Set the style if there was no error generating it
if boldTopRow {
err = xlsx.SetRowStyle(worksheetName, 1, 1, headerStyle)
if err != nil {
fmt.Printf("Error setting header style : '%s'\n", err)
}
}
}
if autoWidth {
err = SetColAutoWidth(xlsx, worksheetName)
if err != nil {
fmt.Printf("Error setting auto width : '%s'\n", err)
}
}
}
// Close off the file
if err := xlsx.SaveAs(outputFilename); err != nil {
log.Fatal(err)
}
return
}
// Check that the first element is what we expected // Check that the first element is what we expected
if _, ok := vslice[0].(orderedmap.OrderedMap); !ok { if _, ok := vslice[0].(orderedmap.OrderedMap); !ok {
error := fmt.Sprintf("Type of first vslice element is not an ordered map. It appears to be '%v'\n", reflect.TypeOf(vslice[0])) error := fmt.Sprintf("Type of first vslice element is not an ordered map. It appears to be '%v'\n", reflect.TypeOf(vslice[0]))
@@ -196,13 +243,13 @@ func main() {
}) })
if err2 != nil { if err2 != nil {
fmt.Printf("Error generating header style : '%s'\n", err2) fmt.Printf("Error generating header style : '%s'\n", err2)
} } else {
// Set the style if there was no error generating it
// Set the style if boldTopRow {
if boldTopRow { err = xlsx.SetRowStyle(worksheetName, 1, 1, headerStyle)
err = xlsx.SetRowStyle(worksheetName, 1, 1, headerStyle) if err != nil {
if err != nil { fmt.Printf("Error setting header style : '%s'\n", err)
fmt.Printf("Error setting header style : '%s'\n", err) }
} }
} }