csvxl

package
v0.2.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 14 Imported by: 1

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 (most common; used as fallback for certain detected encodings) - Big5 (Traditional Chinese) - ASCII - Various other encodings. Unknown or unrecognized encodings will be reported as errors by `DetectEncoding`.

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)
if err := csvxl.CsvToExcel([]string{"file1.csv", "file2.csv"}, nil, "output.xlsx"); err != nil {
    panic(err)
}

// Convert with explicit encoding
if err := csvxl.CsvToExcel([]string{"file1.csv"}, nil, "output.xlsx", csvxl.UTF8); err != nil {
    panic(err)
}

// Read CSV file to string with auto-detection
csvString, err := csvxl.ReadCsvToString("myfile.csv")
if err != nil {
	// Handle error
}

// Detect encoding of a specific file
encoding, err := insyra.DetectEncoding("myfile.csv")
if err != nil {
	// Unknown encoding or detection error; handle appropriately
}

Index

Constants

View Source
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) error

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

func CsvToExcel(csvFiles []string, sheetNames []string, output string, csvEncoding ...string) error

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 EachCsvToOneExcel added in v0.1.0

func EachCsvToOneExcel(dir string, output string, encoding ...string) error

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

func EachExcelToCsv(dir string, outputDir string) error

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".

func ExcelToCsv

func ExcelToCsv(excelFile string, outputDir string, csvNames []string, onlyContainSheets ...string) error

ExcelToCsv splits an Excel file into multiple CSV files, one per sheet. If customNames is provided, it uses them as CSV filenames; otherwise, it uses the sheet names.

func ReadCsvToString added in v0.2.10

func ReadCsvToString(filePath string, encoding ...string) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL