docs.sheetjs.com/docz/static/pandas/SheetJSPandas.py

26 lines
571 B
Python
Raw Normal View History

2024-01-30 09:27:22 +00:00
#!/usr/bin/env python3
2023-07-30 03:17:31 +00:00
2024-01-30 09:27:22 +00:00
from sheetjs import SheetJSWrapper
2023-07-30 03:17:31 +00:00
2024-01-30 09:27:22 +00:00
def process(path):
with SheetJSWrapper() as sheetjs:
2023-07-30 03:17:31 +00:00
2024-01-30 09:27:22 +00:00
# Parse file
wb = sheetjs.read_file(path)
print(f"Loaded file {path}")
2023-07-30 03:17:31 +00:00
2024-01-30 09:27:22 +00:00
# Get first worksheet name
names = wb.get_sheet_names()
print(f"Reading from sheet {names[0]}")
2023-07-30 03:17:31 +00:00
2024-01-30 09:27:22 +00:00
# Generate DataFrame from first worksheet
df = wb.get_df()
print(df.info())
2023-07-30 03:17:31 +00:00
2024-01-30 09:27:22 +00:00
# Export DataFrame to XLSB
sheetjs.write_df(df, "SheetJSPandas.xlsb", sheet_name="DataFrame")
2023-07-30 03:17:31 +00:00
2024-01-30 09:27:22 +00:00
if("__main__" == __name__):
from sys import argv
process(argv[1])