...
|
...
|
@@ -66,6 +66,23 @@ func (tableService *TableService) ExportDataTable(ctx *domain.Context, cmd *comm |
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
func MakeToInterfaces(fields []*domain.Field) func([]string) []interface{} {
|
|
|
return func(input []string) []interface{} {
|
|
|
output := make([]interface{}, len(input))
|
|
|
for i, v := range input {
|
|
|
if i < len(fields) {
|
|
|
convValue, err := domain.ValueToType(v, fields[i].SQLType)
|
|
|
if err == nil {
|
|
|
output[i] = convValue
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
output[i] = v
|
|
|
}
|
|
|
return output
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (tableService *TableService) ExportDataTableV2(ctx *domain.Context, cmd *command.TablePreviewCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
...
|
...
|
@@ -182,6 +199,7 @@ func exportTableTo(ctx *domain.Context, cmd *command.TablePreviewCommand, table |
|
|
filename := fmt.Sprintf("%v_%v.xlsx", table.Name, time.Now().Format("060102150405"))
|
|
|
path := fmt.Sprintf("public/%v", filename)
|
|
|
excelWriter := excel.NewXLXSWriterTo(domain.Fields(table.Fields(false)).NameArrayString(), dataTable.Data) //
|
|
|
excelWriter.ToInterfaces = MakeToInterfaces(table.Fields(false))
|
|
|
if err = excelWriter.Save(path); err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
...
|
...
|
|