# sheet2dict
A simple XLSX/CSV to dictionary converter
## Installing
To install the package from pip, first run:
```bash
python3 -m pip install --no-cache-dir sheet2dict
```
Required pip packages for sheet2doc: csv, openpyxl
## Usage
This library has 2 main features: reading a spreadsheet files and converting them to array of python dictionaries.
### - XLSX
Use `xlsx_to_dict()` method when converting form spreadsheets.
Supported file formats for spreadsheets are: .xlsx,.xlsm,.xltx,.xltm
```python3
# Import the library
from sheet2dict import Worksheet
# Create an object
ws = Worksheet()
# Convert
ws.xlsx_to_dict(path='inventory.xlsx')
# object.headers() returns first row with the data in a spreadsheet
print(ws.headers())
# object.sheet_items returns converted rows as dictionaries in the array
print(ws.sheet_items)
```
You can parse data when worksheet is an object
```python3
# Import the library
from sheet2dict import Worksheet
# Example: read spreadsheet as object
path = 'inventory.xlsx'
xlsx_file = open(path, 'rb')
xlsx_file = BytesIO(xlsx_file.read())
# Parse spreadsheet from object
ws = Worksheet()
ws.xlsx_to_dict(path=xlsx_file)
print(ws.headers())
```
### - CSV
Use `csv_to_dict()` method when converting form csv.
CSV is a format with many variations, better handle encodings and delimiters on user side and not within module itself.
```python3
# Import the library
from sheet2dict import Worksheet
# Create an object
ws = Worksheet()
# Read CSV file
csv_file = open('inventory.csv', 'r', encoding='utf-8-sig')
# Convert
ws.csv_to_dict(csv_file=csv_file, delimiter=';')
# object.headers() returns first row with the data in a spreadsheet
print(ws.headers())
# object.sheet_items returns converted rows as dictionaries in the array
print(ws.sheet_items)
```
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共8个文件
txt:3个
pkg-info:2个
cfg:1个
资源分类:Python库 所属语言:Python 资源全名:sheet2dict-0.0.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
sheet2dict-0.0.1.tar.gz (8个子文件)
sheet2dict-0.0.1
PKG-INFO 3KB
pyproject.toml 104B
sheet2dict.egg-info
PKG-INFO 3KB
SOURCES.txt 170B
top_level.txt 1B
dependency_links.txt 1B
setup.cfg 525B
README.md 2KB
共 8 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功