CSVHandler — Aspose.Cells FOSS for Python API Reference
aspose-cells-foss provides CSV import and export through the CSVHandler class and two companion option classes. Module-level convenience functions are also available for simple use cases.
Package: aspose.cells_foss
from aspose.cells_foss import CSVHandler, CSVLoadOptions, CSVSaveOptions
from aspose.cells_foss import load_csv_workbook, save_workbook_as_csvCSVLoadOptions
Options that control how a CSV file is parsed when loading.
Constructor
CSVLoadOptions()Properties
CSVLoadOptions has no configurable properties. Pass an instance to CSVHandler.load_csv() to use default parsing behavior.
CSVSaveOptions
Options that control how a workbook is serialized to CSV.
Constructor
CSVSaveOptions()Properties
CSVSaveOptions has no configurable properties. Pass an instance to CSVHandler.save_csv() to use default serialization behavior.
CSVHandler
CSVHandler contains only static methods and is never instantiated.
CSVHandler.save_csv
CSVHandler.save_csv(workbook, file_path: str, options: CSVSaveOptions | None = None) -> NoneSaves the specified worksheet of workbook to a CSV file at file_path. If options is None, default CSVSaveOptions are used.
CSVHandler.save_csv_to_string
CSVHandler.save_csv_to_string(workbook, options: CSVSaveOptions | None = None) -> strSerializes the worksheet to a CSV string and returns it. No file is written.
CSVHandler.load_csv
CSVHandler.load_csv(workbook, file_path: str, options: CSVLoadOptions | None = None) -> NoneParses the CSV file at file_path and loads its data into the first worksheet of workbook, replacing any existing content. If options is None, default CSVLoadOptions are used.
CSVHandler.load_csv_from_string
CSVHandler.load_csv_from_string(workbook, csv_content: str, options: CSVLoadOptions | None = None) -> NoneParses a CSV string and loads its data into the first worksheet of workbook.
Module Functions
load_csv_workbook
load_csv_workbook(file_path: str, options: CSVLoadOptions | None = None) -> WorkbookCreates a new Workbook, loads the CSV file into its first worksheet, and returns the workbook. Equivalent to creating a Workbook and calling CSVHandler.load_csv(wb, file_path, options).
save_workbook_as_csv
save_workbook_as_csv(workbook, file_path: str, options: CSVSaveOptions | None = None) -> NoneConvenience wrapper around CSVHandler.save_csv(workbook, file_path, options).
Example
The following example loads a comma-delimited CSV file and saves it back with a semicolon delimiter.
from aspose.cells_foss import load_csv_workbook, CSVLoadOptions, CSVSaveOptions, save_workbook_as_csv
# Load the original CSV with default options
load_opts = CSVLoadOptions()
wb = load_csv_workbook("input.csv", options=load_opts)
# Inspect what was loaded
ws = wb.worksheets[0]
print(f"Cell A1: {ws.cells['A1'].value}")
# Save as CSV with default options
save_opts = CSVSaveOptions()
save_workbook_as_csv(wb, "output.csv", options=save_opts)