Exporter service

This service is able to export business data to various file formats. Currently, we support 2 file formats: XLSX and CSV.

Register the service into your main.go file:

registry.ServiceProviderExporter()
1

Access the service:

service.DI().Exporter()
1

Input data should be filled in as follows:

sheet := "sheet 1"
headers := []string{"Header 1", "Header 2"}

rows := make([][]interface{}, 0)

var firstRow []interface{}
firstRow = append(firstRow, "cell 1", "cell 2")
rows = append(rows, firstRow)

var secondRow []interface{}
secondRow = append(secondRow, "cell 1", "cell 2")
rows = append(rows, secondRow)
1
2
3
4
5
6
7
8
9
10
11
12

Use XLSXExportToByte() function to convert raw data to Excel file and return it as a byte slice:

xlsxBytes, err := exporterService.XLSXExportToByte(sheet, headers, rows)
1

Use XLSXExportToFile() function for converting raw data to Excel file and save it in the given path:

err := exporterService.XLSXExportToFile(sheet, headers, rows, filePath)
1

Use CSVExportToByte() function to convert raw data to CSV file and return it as a byte slice:

csvBytes, err := exporterService.CSVExportToByte(headers, rows)
1

Using CSVExportToFile() function for converting raw data to CSV file and save it in the given path:

err := exporterService.XLSXExportToFile(headers, rows, filePath)
1