added interactive component to control title and filename
This commit is contained in:
88
main.go
88
main.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -10,13 +11,40 @@ import (
|
||||
"github.com/signintech/gopdf"
|
||||
)
|
||||
|
||||
const title string = "Teilnahmeliste der StugA Lehramt GO-Vollversammlung 07.04.2026"
|
||||
|
||||
func main() {
|
||||
// Prepare data
|
||||
file, err := os.Open("list.csv")
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
fmt.Print("Moin! Dieses kleine Tool erstellt dir eine Teilnahmeliste als PDF, welche du an den AStA schicken kannst, um nach einer Vollversammlung den StugA bestätigen zu lassen.\n\n")
|
||||
fmt.Print("Wahrscheinlich/hoffentlich habt ihr für die Teilnahmeliste eine Umfrage auf Nextcloud erstellt, in welcher sich Leute eintragen konnten. Falls dem so ist -- perfekt! Exportiere die Daten aus Nextcloud im CSV-Format und packe sie in den selben Ordner, in welchem auch dieses Programm liegt.\n\n")
|
||||
fmt.Println("Gib bitte jetzt den Namen der Datei ein, z.B. 'liste.csv':")
|
||||
|
||||
scanner.Scan()
|
||||
err := scanner.Err()
|
||||
if err != nil {
|
||||
log.Fatalln("Error while reading file: " + err.Error())
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
fileName := scanner.Text()
|
||||
|
||||
fmt.Println("Danke! Jetzt brauche ich noch einen Titel, wie z.B. 'Teilnahmeliste der StugA Lehramt GO-Vollversammlung 01.01.2026':")
|
||||
|
||||
scanner.Scan()
|
||||
err2 := scanner.Err()
|
||||
if err2 != nil {
|
||||
log.Fatalln(err2.Error())
|
||||
}
|
||||
title := scanner.Text()
|
||||
|
||||
fmt.Println("Deine Datei wird erstellt...")
|
||||
|
||||
createPdf(fileName, title)
|
||||
|
||||
fmt.Println("Die Datei wurde erstellt! Das Programm schließt sich jetzt.")
|
||||
}
|
||||
|
||||
func createPdf(fileName, title string) {
|
||||
// Prepare data
|
||||
file, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
log.Fatalln("Fehler beim Öffnen der Datei: " + err.Error())
|
||||
}
|
||||
|
||||
reader := csv.NewReader(file)
|
||||
@@ -24,11 +52,9 @@ func main() {
|
||||
records, errRecords := reader.ReadAll()
|
||||
|
||||
if errRecords != nil {
|
||||
log.Fatalln("Error while parsing file: " + errRecords.Error())
|
||||
log.Fatalln("Fehler beim Auslesen der Datei: " + errRecords.Error())
|
||||
}
|
||||
|
||||
log.Println("hey")
|
||||
|
||||
defer file.Close()
|
||||
|
||||
// Prepare document
|
||||
@@ -52,13 +78,9 @@ func main() {
|
||||
record[3],
|
||||
record[5],
|
||||
})
|
||||
// if index%31 == 0 {
|
||||
// pdf.AddPage()
|
||||
// }
|
||||
}
|
||||
|
||||
iterations := math.Ceil(float64(len(tableEntries)) / 31.0)
|
||||
fmt.Println(iterations)
|
||||
|
||||
for i := 0; i < int(iterations); i += 1 {
|
||||
// create each page here
|
||||
@@ -95,48 +117,6 @@ func main() {
|
||||
pdf.Cell(nil, fmt.Sprintf("%d", int(i+1)))
|
||||
}
|
||||
|
||||
// table.SetTableStyle(gopdf.CellStyle{
|
||||
// BorderStyle: gopdf.BorderStyle{
|
||||
// Top: true,
|
||||
// Left: true,
|
||||
// Bottom: true,
|
||||
// Right: true,
|
||||
// Width: 1.0,
|
||||
// },
|
||||
// FillColor: gopdf.RGBColor{R: 255, G: 255, B: 255},
|
||||
// TextColor: gopdf.RGBColor{R: 0, G: 0, B: 0},
|
||||
// FontSize: 10,
|
||||
// })
|
||||
|
||||
// // Set the style for table header
|
||||
// table.SetHeaderStyle(gopdf.CellStyle{
|
||||
// BorderStyle: gopdf.BorderStyle{
|
||||
// Top: true,
|
||||
// Left: true,
|
||||
// Bottom: true,
|
||||
// Right: true,
|
||||
// Width: 2.0,
|
||||
// RGBColor: gopdf.RGBColor{R: 100, G: 150, B: 255},
|
||||
// },
|
||||
// FillColor: gopdf.RGBColor{R: 255, G: 200, B: 200},
|
||||
// TextColor: gopdf.RGBColor{R: 255, G: 100, B: 100},
|
||||
// Font: "font2",
|
||||
// FontSize: 12,
|
||||
// })
|
||||
|
||||
// table.SetCellStyle(gopdf.CellStyle{
|
||||
// BorderStyle: gopdf.BorderStyle{
|
||||
// Right: true,
|
||||
// Bottom: true,
|
||||
// Width: 0.5,
|
||||
// RGBColor: gopdf.RGBColor{R: 0, G: 0, B: 0},
|
||||
// },
|
||||
// FillColor: gopdf.RGBColor{R: 255, G: 255, B: 255},
|
||||
// TextColor: gopdf.RGBColor{R: 0, G: 0, B: 0},
|
||||
// Font: "font1",
|
||||
// FontSize: 10,
|
||||
// })
|
||||
|
||||
// Finish document
|
||||
pdf.WritePdf("vvliste.pdf")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user