feat: add filename to exported exceltable
This commit is contained in:
parent
a6e2986143
commit
b1d345b152
4 changed files with 11 additions and 8 deletions
2
app.go
2
app.go
|
|
@ -166,7 +166,7 @@ func (a *App) makeChoice() {
|
|||
case "start rdp connection":
|
||||
a.startRDPConnection()
|
||||
case "export":
|
||||
tw.ExportSummary()
|
||||
tw.ExportSummary(a.flags.ExportName)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
3
cmd.go
3
cmd.go
|
|
@ -55,7 +55,7 @@ func (a *App) showCommand() *cobra.Command {
|
|||
Run: func(cmd *cobra.Command, args []string) {
|
||||
tw := NewTimeWarrior()
|
||||
if a.flags.ShowExport {
|
||||
tw.ExportSummary()
|
||||
tw.ExportSummary(a.flags.ExportName)
|
||||
}
|
||||
if a.flags.ShowWeek {
|
||||
tw.ShowSummary(":week")
|
||||
|
|
@ -70,6 +70,7 @@ func (a *App) showCommand() *cobra.Command {
|
|||
cmd.Flags().BoolVarP(&a.flags.ShowWeek, "week", "w", false, "show timewarrior week summary")
|
||||
cmd.Flags().BoolVarP(&a.flags.ShowMonth, "month", "m", false, "show timewarrior month summary")
|
||||
cmd.Flags().BoolVarP(&a.flags.ShowExport, "export", "e", false, "export timewarrior timetable")
|
||||
cmd.Flags().StringVarP(&a.flags.ExportName, "name", "n", "Arbeitszeiten.xlsx", "name of exported excel table")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ type Flags struct {
|
|||
ShowWeek bool
|
||||
ShowMonth bool
|
||||
ShowExport bool
|
||||
ExportName string
|
||||
}
|
||||
|
||||
func loadConfig() (Config, error) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ type TimeEntry struct {
|
|||
Tag string
|
||||
}
|
||||
|
||||
func (t *TimeWarrior) ExportSummary() error {
|
||||
func (t *TimeWarrior) ExportSummary(name string) error {
|
||||
fmt.Println("Export Timetable")
|
||||
exportCommand := exec.Command("timew", "summary", ":year")
|
||||
output, err := exportCommand.Output()
|
||||
|
|
@ -122,7 +122,7 @@ func (t *TimeWarrior) ExportSummary() error {
|
|||
case "break":
|
||||
duration, _ := parseDuration(entry.Duration)
|
||||
summary.BreakDuration += duration
|
||||
case "uni", "free", "krank", "urlaub":
|
||||
case "uni", "free", "krank", "urlaub", "feiertag":
|
||||
summary.Tag = entry.Tag
|
||||
}
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ func (t *TimeWarrior) ExportSummary() error {
|
|||
fmt.Printf("%+v\n", entry)
|
||||
}
|
||||
|
||||
err = writeExcelSheet(excelEntries)
|
||||
err = writeExcelSheet(excelEntries, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -210,7 +210,7 @@ func formatDuration(d time.Duration) string {
|
|||
return fmt.Sprintf("%d:%02d:%02d", h, m, s)
|
||||
}
|
||||
|
||||
func writeExcelSheet(entries []ExcelEntry) error {
|
||||
func writeExcelSheet(entries []ExcelEntry, name string) error {
|
||||
sort.Slice(entries, func(i, j int) bool {
|
||||
dateI, _ := time.Parse("2006-01-02", entries[i].Date)
|
||||
dateJ, _ := time.Parse("2006-01-02", entries[j].Date)
|
||||
|
|
@ -230,7 +230,6 @@ func writeExcelSheet(entries []ExcelEntry) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Überschriften setzen
|
||||
f.SetCellValue(sheetName, "B1", "Arbeitszeiten "+sheetName)
|
||||
f.SetCellValue(sheetName, "B3", "Datum")
|
||||
f.SetCellValue(sheetName, "D3", "Arbeitszeit")
|
||||
|
|
@ -303,6 +302,8 @@ func writeExcelSheet(entries []ExcelEntry) error {
|
|||
text = "Hochschule"
|
||||
case "urlaub":
|
||||
text = "Urlaub"
|
||||
case "feiertag":
|
||||
text = "Feiertag"
|
||||
default:
|
||||
text = ""
|
||||
}
|
||||
|
|
@ -313,7 +314,7 @@ func writeExcelSheet(entries []ExcelEntry) error {
|
|||
}
|
||||
|
||||
f.SetActiveSheet(index)
|
||||
if err := f.SaveAs("Test.xlsx"); err != nil {
|
||||
if err := f.SaveAs(name); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue