feat: draft of excel export
This commit is contained in:
@@ -34,6 +34,11 @@ func ErrorDialog(title string, message string) {
|
||||
application.ErrorDialog().AttachToWindow(currentWindow).SetTitle(title).SetMessage(message).Show()
|
||||
}
|
||||
|
||||
func SaveFileDialog(title string) {
|
||||
func SaveFileDialog(title string, filename string) (string, error) {
|
||||
checkInit()
|
||||
selection, err := application.SaveFileDialog().AttachToWindow(currentWindow).SetFilename(filename).PromptForSingleSelection()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return selection, nil
|
||||
}
|
||||
|
||||
@@ -1 +1,37 @@
|
||||
package excel
|
||||
|
||||
import (
|
||||
"app/internal/services"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"log/slog"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type TableHeaders struct {
|
||||
Headers []string
|
||||
IgnoredFieldsIndices []uint
|
||||
}
|
||||
|
||||
func ExportEntityToSpreadsheet[T any](filename, sheetName string, entity T, service services.Service[T]) error {
|
||||
file := excelize.NewFile()
|
||||
defer func() {
|
||||
if err := file.Close(); err != nil {
|
||||
slog.Error("Error while closing excel file: ", err)
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExportHeaders(entity any) TableHeaders {
|
||||
headers := TableHeaders{}
|
||||
v := reflect.TypeOf(entity)
|
||||
for i := range v.NumField() {
|
||||
field := v.Field(i)
|
||||
displayName := field.Tag.Get("displayName")
|
||||
if displayName != "" {
|
||||
|
||||
}
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ var Entities = []any{
|
||||
}
|
||||
|
||||
type Post struct {
|
||||
Id uint `gorm:"primaryKey"`
|
||||
Text string
|
||||
Id uint `gorm:"primaryKey"`
|
||||
Text string `displayName:"Текст"`
|
||||
CreatedAt int64 `gorm:"autoCreateTime" displayName:"Дата публикации" cellType:"timestamp"`
|
||||
}
|
||||
|
||||
// Author A sample of comment
|
||||
type Author struct {
|
||||
Id uint `gorm:"primaryKey"`
|
||||
Name string
|
||||
|
||||
Reference in New Issue
Block a user