Documentation
¶
Overview ¶
Package file provides functionality for reading, processing, and saving CSV files. It includes features for inferring column data types and saving the data to Excel files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CSV ¶
type CSV struct {
// FilePath is the path to the CSV file.
FilePath string
// Delimiter is the character used to separate fields in the CSV file.
Delimiter rune
// Columns is a slice of Column information.
Headers []Column
// Records is a slice of slices, where each inner slice represents a row of data.
// The data type of the elements within the inner slices can vary based on type inference.
Records [][]interface{}
}
CSV represents a CSV file and its parsed data.
func New ¶
New creates a new CSV struct. It initializes the CSV struct with the given file path and delimiter.
func NewFromRecords ¶
func (*CSV) ConvertColumnTypes ¶
func (c *CSV) ConvertColumnTypes()
ConvertColumnTypes attempts to convert string values in the Records to their inferred types (float or integer). This function relies on the inferColumnTypes method to determine the appropriate type for each column.
func (*CSV) GetHeaderNames ¶
GetHeaderNames returns a Slice with the names of the columns in the CSV file.
func (*CSV) Read ¶
Read reads the CSV file, parses its contents, and populates the CSV struct. It infers column names from the first row and stores the data in the Records field. Returns an error if the file cannot be opened or read.
func (*CSV) SaveAsExcel ¶
SaveAsExcel saves the CSV data to an Excel file. It creates a new Excel file and writes the column names and data records to the specified sheet. Returns an error if the file cannot be created or written to.
type Column ¶
type Column struct {
// Name is the name of the column, typically read from the header row.
Name string
// Type is the inferred data type of the column.
Type ColumnType
}
Column represents a column in the CSV file, including its name and inferred data type.