Skip to content
项目

关于

Rust 库 calamine 的 Python 绑定,可用于读取 Excel 和 ODF 文件。

开发工具

这些数字如何统计

实测星标增长

24小时
+1
7天
+3
15天
+9
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

python-calamine

PyPI - Version Conda Version Python Version from PEP 621 TOML

Python binding for beautiful Rust's library for reading excel and odf file - calamine.

Is used

Installation

Pypi:

pip install python-calamine

Conda:

conda install -c conda-forge python-calamine

Example

from python_calamine import CalamineWorkbook

workbook = CalamineWorkbook.from_path("file.xlsx")
workbook.sheet_names
# ["Sheet1", "Sheet2"]

workbook.get_sheet_by_name("Sheet1").to_python()
# [
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ]

By default, calamine skips empty rows/cols before data. For suppress this behaviour, set skip_empty_area to False.

from python_calamine import CalamineWorkbook

workbook = CalamineWorkbook.from_path("file.xlsx").get_sheet_by_name("Sheet1").to_python(skip_empty_area=False)
# [
# [",  ",  ",  ",  ",  ",  "],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ]

Workbook document properties, such as the author, are available for xlsx, xlsb, xls and ods files.

from python_calamine import CalamineWorkbook

properties = CalamineWorkbook.from_path("file.xlsx").workbook_properties
properties.creator
# "John"
properties.last_modified_by
# "Jane"
properties.modified
# datetime.datetime(2024, 6, 20, 14, 22, tzinfo=datetime.timezone.utc)
properties.custom_properties
# {"Department": "Finance"}

Pandas 2.2 and above have built-in support of python-calamine.

Also, you can find additional examples in tests.

Development

You'll need rust installed.

# clone this repo or your fork
git clone [email protected]:dimastbk/python-calamine.git
cd python-calamine
# create a new virtual env
python3 -m venv env
source env/bin/activate
# install dev dependencies and install python-calamine
pip install --group dev -e .  # required pip 25.1 and above
# lint code
pre-commit run --all-files
# test code
pytest

探索相关项目

加载中…