Skip to content

The xlsx modul

gamslib.objectcsv.xlsx

Utilities to convert object and datastream CSV files to XLSX format and back.

Provides functions to read CSV files, convert them to XLSX spreadsheets with separate sheets, and split XLSX files back into object and datastream CSV files.

read_csv

read_csv(csvfile, skip_header=True)

Read a CSV file and return a list of rows.

PARAMETER DESCRIPTION
csvfile

Path to the CSV file.

TYPE: Path

skip_header

If True, skip the first row (header).

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[list[str]]

list[list[str]]: List of rows, each row as a list of strings.

csv_to_xlsx

csv_to_xlsx(object_csv, ds_csv, output_file)

Convert object and datastream CSV files to a single XLSX file.

PARAMETER DESCRIPTION
object_csv

Path to the object metadata CSV file.

TYPE: Path

ds_csv

Path to the datastream metadata CSV file.

TYPE: Path

output_file

Path for the output XLSX file.

TYPE: Path

RETURNS DESCRIPTION
Path

Path to the created XLSX file.

TYPE: Path

Notes
  • Object metadata is written to the "Object Metadata" sheet.
  • Datastream metadata is written to the "Datastream Metadata" sheet.

xlsx_to_csv

xlsx_to_csv(xlsx_path, obj_csv_path, ds_csv_path)

Convert a XLSX metadata file to two CSV files: object.csv and datastreams.csv.

PARAMETER DESCRIPTION
xlsx_path

Path to the XLSX file containing metadata.

TYPE: Path

obj_csv_path

Path for the output object metadata CSV file.

TYPE: Path

ds_csv_path

Path for the output datastream metadata CSV file.

TYPE: Path

RETURNS DESCRIPTION
tuple[Path, Path]

tuple[Path, Path]: Paths to the created object and datastream CSV files.

Notes
  • Reads "Object Metadata" and "Datastream Metadata" sheets from the XLSX file.
  • Writes each sheet to its respective CSV file.