ESC
Type to search...
S
Soli Docs

Spreadsheet Class

Import and parse CSV and Excel files for data processing.

CSV Parsing

Spreadsheet.csv(content)

Parses a CSV string and returns an array of hashes (one hash per row).

csv_content = "name,email,age\nAlice,[email protected],30"
data = Spreadsheet.csv(csv_content)
print(data[0]["name"])  # "Alice"
Spreadsheet.csv_file(path)

Reads and parses a CSV file from disk.

data = Spreadsheet.csv_file("users.csv")
for row in data
  print(row["email"])
end

Excel Parsing

Spreadsheet.excel(path)

Reads and parses an Excel (.xlsx) file. Returns an array of hashes using the first row as headers.

data = Spreadsheet.excel("report.xlsx")
for row in data
  print(row["Name"])
end

Export Functions

Spreadsheet.to_csv(data)

Converts an array of hashes to a CSV string.

data = [{"name": "Alice", "age": "30"}, {"name": "Bob", "age": "25"}]
csv = Spreadsheet.to_csv(data)
Spreadsheet.csv_write(data, path)

Writes an array of hashes to a CSV file.

data = [{"name": "Alice", "score": "95"}, {"name": "Bob", "score": "87"}]
Spreadsheet.csv_write(data, "output.csv")
Spreadsheet.excel_write(data, path)

Writes an array of hashes to an Excel (.xlsx) file.

data = [{"name": "Alice", "score": "95"}, {"name": "Bob", "score": "87"}]
Spreadsheet.excel_write(data, "output.xlsx")