Documentation
¶
Overview ¶
`csvxl` package provides functions for converting between CSV and Excel formats.
Key Features: - Convert multiple CSV files to a single Excel workbook with separate sheets - Split Excel workbooks into multiple CSV files - Automatic encoding detection for CSV files - Support for UTF-8, Big5, and other common text encodings - Batch processing of files in directories
Encoding Support: The package now supports automatic encoding detection by default. When no encoding is explicitly specified, the package will automatically detect the encoding of CSV files using charset detection algorithms. Supported encodings include: - UTF-8 (default fallback) - Big5 (Traditional Chinese) - ASCII - Various other encodings with automatic fallback to UTF-8
You can still explicitly specify an encoding using the constants: - csvxl.UTF8 for UTF-8 encoding - csvxl.Big5 for Big5 encoding - csvxl.Auto for automatic detection (default)
Example usage:
// Convert CSV files to Excel with auto-detection (default)
csvxl.CsvToExcel([]string{"file1.csv", "file2.csv"}, nil, "output.xlsx")
// Convert with explicit encoding
csvxl.CsvToExcel([]string{"file1.csv"}, nil, "output.xlsx", csvxl.UTF8)
// Detect encoding of a specific file
encoding, err := csvxl.DetectEncoding("myfile.csv")
Index ¶
- Constants
- func AppendCsvToExcel(csvFiles []string, sheetNames []string, existingFile string, ...)
- func CsvToExcel(csvFiles []string, sheetNames []string, output string, csvEncoding ...string)
- func DetectEncoding(csvFile string) (string, error)
- func EachCsvToOneExcel(dir string, output string, encoding ...string)
- func EachExcelToCsv(dir string, outputDir string)
- func ExcelToCsv(excelFile string, outputDir string, csvNames []string, ...)
Constants ¶
const ( UTF8 = "utf-8" Big5 = "big5" Auto = "auto" )
CsvEncoding Options
Variables ¶
This section is empty.
Functions ¶
func AppendCsvToExcel ¶
func AppendCsvToExcel(csvFiles []string, sheetNames []string, existingFile string, csvEncoding ...string)
Append CSV files to an existing Excel file, supporting custom sheet names. If the sheet name is not specified, the file name of the CSV file will be used. If the sheet is exists, it will be overwritten. If csvEncoding is not specified, auto-detection will be used.
func CsvToExcel ¶
Convert multiple CSV files to an Excel file, supporting custom sheet names. If the sheet name is not specified, the file name of the CSV file will be used. If csvEncoding is not specified, auto-detection will be used.
func DetectEncoding ¶ added in v0.2.6
DetectEncoding automatically detects the encoding of a CSV file Returns the detected encoding as a string, or an error if detection fails
func EachCsvToOneExcel ¶ added in v0.1.0
EachCsvToOneExcel converts each CSV file in the given directory to an Excel file. The output Excel file will be saved in the given output path. If encoding is not specified, auto-detection will be used.
func EachExcelToCsv ¶ added in v0.1.0
EachExcelToCsv converts each Excel file in the given directory to CSV files. The output CSV files will be saved in the given output directory. The CSV files will be named as the Excel file name plus the sheet name plus ".csv", for example, "ExcelFileName_SheetName.csv".
Types ¶
This section is empty.