67 lines
1.2 KiB
Go
67 lines
1.2 KiB
Go
package xlsx
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
)
|
|
|
|
type Plan = [7][3]struct {
|
|
Text string
|
|
Date time.Time
|
|
}
|
|
|
|
func Load() (Plan, error) {
|
|
f, err := excelize.OpenFile("./plan.xlsx")
|
|
defer func() {
|
|
err := f.Close()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
}()
|
|
if err != nil {
|
|
return Plan{}, err
|
|
}
|
|
var plan [7][3]struct {
|
|
Text string
|
|
Date time.Time
|
|
}
|
|
today := time.Now().Format("01-02-06")
|
|
v := ""
|
|
offset := 1
|
|
for v != today {
|
|
offset++
|
|
v, err = f.GetCellValue("Menüplan", "A"+strconv.Itoa(offset))
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
}
|
|
for x := 0; x <= 2; x++ {
|
|
for y := 0; y <= 6; y++ {
|
|
plan[y][x] = struct {
|
|
Text string
|
|
Date time.Time
|
|
}{}
|
|
plan[y][x].Text, err = f.GetCellValue("Menüplan", string([]rune{rune('B' + x)})+strconv.Itoa(y+offset))
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
continue
|
|
}
|
|
datestr, err := f.GetCellValue("Menüplan", "A"+strconv.Itoa(y+offset))
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
continue
|
|
}
|
|
time, err := time.Parse("01-02-06", datestr)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
continue
|
|
}
|
|
plan[y][x].Date = time
|
|
}
|
|
}
|
|
return plan, err
|
|
}
|