一个简洁的Excel处理工具包
Project description
brief-excel
一个简洁的Excel处理工具包,提供简洁的API用于创建、读取、编辑Excel文件,支持工作表管理、单元格操作、图片插入等功能。
📋 目录
✨ 特性
- 简洁的API设计:链式调用,代码清晰易读
- 完整的工作表管理:创建、复制、移动、删除工作表
- 灵活的单元格操作:支持单个单元格、整行、整列、区域数据的读写
- 图片插入功能:支持在单元格中插入图片,可调整大小和位置
- 错误处理:详细的异常信息,便于调试
- 数据缓冲区:提供临时数据存储,方便数据传递
🚀 快速开始
前提条件
- Python 3.7 或更高版本
- 基本的Python编程知识
安装
从PyPI安装(推荐)
pip install brief_excel
从源码安装
git clone https://gitee.com/hh66dw/brief_excel.git
cd brief_excel
pip install -e .
📖 使用指南
基本用法
from brief_excel import BriefExcel
# 创建Excel文件
excel = BriefExcel("example").create()
# 添加工作表
excel.ws_append("新工作表", 2)
# 定位到第一个工作表
excel.ws_location(1)
# 写入数据到单元格
excel.cell_write(1, 1, "Hello, World!")
# 写入整行数据
excel.cell_row_write(2, 1, ["A", "B", "C", "D"])
# 保存文件
excel.save()
高级用法
from brief_excel import BriefExcel
# 加载现有Excel文件
excel = BriefExcel().load("existing_file")
# 复制工作表
excel.ws_location("Sheet1").ws_copy()
# 移动工作表
excel.ws_move(3)
# 读取区域数据
data = excel.cell_area_read(1, 1, 5, 3).info()
print(data)
# 插入图片
excel.insert_pic(1, 1, "test_images/red_square_100x100.png", 100, 100)
# 保存修改
excel.save()
📚 API 文档
主要类
BriefExcel
主要的Excel操作类。
__init__(name: str = None)
初始化BriefExcel实例。
set_name(name: str) -> BriefExcel
设置Excel文件名。
create() -> BriefExcel
创建新的Excel文件。
load(fpn: str = None) -> BriefExcel
加载现有的Excel文件。
save(fpn: str = None)
保存Excel文件。
ws_append(name: str = 'Sheet', num: int = 1) -> BriefExcel
添加工作表。
ws_location(title_or_num: str | int, debug = True) -> BriefExcel
定位到指定工作表。
ws_move(index: int, title_or_num: str | int = None) -> BriefExcel
移动当前工作表位置。
ws_copy(title_or_num: str | int = None) -> BriefExcel
复制工作表。
ws_delete(title_or_num: str | int = None) -> BriefExcel
删除当前工作表。
cell_location(row: int, col: int = 0, debug = True) -> BriefExcel
定位到指定单元格。
cell_write(row: int = 0, col: int = 0, data: str = None, debug = True) -> BriefExcel
写入单个单元格数据。
cell_row_write(row: int, col: int = 1, datas: list = None, debug = True) -> BriefExcel
写入整行数据。
cell_row_read(row: int, col_start = 1, col_end = 1) -> BriefExcel
读取整行数据。
cell_col_write(row: int = 1, col: int = 1, datas: list = None) -> BriefExcel
写入整列数据。
cell_col_read(col: int = 0, row_start = 1, row_end = 1) -> BriefExcel
读取整列数据。
cell_area_write(row: int, col: int = 1, datas: list[list] = None) -> BriefExcel
写入区域数据。
cell_area_read(row_start: int = 0, col_start: int = 0, row_end = 0, col_end = 0) -> BriefExcel
读取区域数据。
insert_pic(row: int, col: int = 0, path: str = None, width: int = 720, height: int = 1280, width_scale: float = 0.14, height_scale: float = 0.78, width_min: float = 8.43, height_min: float = 15, debug = True) -> BriefExcel
插入单张图片。
insert_pic_row(row: int, col: int = 0, paths: str = None, width: int = 720, height: int = 1280)
以行插入图片。
insert_pic_col(row: int = 0, col: int = 1, paths: str = None, width: int = 720, height: int = 1280)
以列插入图片。
💻 开发
项目结构
brief_excel/
├── src/
│ └── brief_excel/
│ ├── __init__.py
│ └── module.py
├── tests/
│ ├── test.py
│ └── test_images/
├── pyproject.toml
├── requirements.txt
├── README.md
└── LICENSE
🤝 贡献指南
我们欢迎各种形式的贡献,包括但不限于代码、文档、测试用例、问题报告和功能建议。
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
请确保代码风格一致,并通过所有测试。
📄 许可证
本项目基于 MIT 许可证发行。详情请参阅 LICENSE 文件。
📞 联系方式
- 项目维护者: hh66dw
- 邮箱: hh66dw@163.com
- 项目链接: https://gitee.com/hh66dw/brief_excel
- 问题反馈: https://gitee.com/hh66dw/brief_excel/issues
如果这个项目对您有帮助,请给个 ⭐️ 星标支持!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brief_excel-1.0.1.tar.gz.
File metadata
- Download URL: brief_excel-1.0.1.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b44f1bfa020138479e4ea7c4e3fcd50b1c62752cbc249c1a06344e16d0fc13aa
|
|
| MD5 |
012104c35b1244cb0e1b260ed2470c5e
|
|
| BLAKE2b-256 |
a762796bba89f4edbf693beee64f212ca95430197dd46fa414bb5463c08748aa
|
File details
Details for the file brief_excel-1.0.1-py3-none-any.whl.
File metadata
- Download URL: brief_excel-1.0.1-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c66c3b1059ac19b08326bf84068aafe75244daaad8e3417632784dfa483956f4
|
|
| MD5 |
16fdce803198dadb618de66bf394c7ba
|
|
| BLAKE2b-256 |
8943fc4e0b3f9a8f9d63dabb490ff5347e14498b20143ed235c4ee4f29e87223
|