No project description provided
Project description
개요
xlsxwriter 를 이용하여 엑셀을 보다 쉽게 작성할 수 있도록 도와주는 라이브러리입니다. 헤더 및 스타일 등을 간단히 지정할 수 있습니다.
설치
pip install simple-excel
사용법
- header 의 key 를 기준으로 데이터를 가공하여 엑셀로 저장합니다.
save_to를 string 으로 지정하면./output디렉터리 아래 파일이 저장됩니다. - 셀 너비는 텍스트 길이에 따라 자동으로 늘어나지만, 완벽하게 최적으로 설정되지는 않습니다. 따라서 엑셀의 자동 조정기능을 통해 너비를 조정해야 합니다.
- 다양한 방식으로 작성할 수 있도록 구현했습니다.
1. 가장 간단한 사용법
# 기본 사용법
simple_excel = SimpleExcel(save_to="test").open()
simple_excel.header = {"이름": "이름", "휴대폰": "휴 대 폰", "가입일": "가입일"}
simple_excel.cell_styles = {"휴대폰": {"num_format": "@"}}
simple_excel.cell_comments = {"휴대폰": "- 를 제거한 후 입력해주세요."}
excel_body = list()
for x in range(1, 100):
excel_body.append({"이름": f"홍길동{x}", "휴대폰": f"0101234567{x:02d}", "가입일": "2025-01-01"})
simple_excel.body = excel_body
simple_excel.write_sheet()
simple_excel.close()
# with 구문 사용법 (close 생략 가능)
with SimpleExcel(save_to="test") as simple_excel:
simple_excel.header = {"이름": "이름", "휴대폰": "휴 대 폰", "가입일": "가입일"}
simple_excel.cell_styles = {"휴대폰": {"num_format": "@"}}
simple_excel.cell_comments = {"휴대폰": "- 를 제거한 후 입력해주세요."}
excel_body = list()
for x in range(1, 100):
excel_body.append({"이름": f"홍길동{x}", "휴대폰": f"0101234567{x:02d}", "가입일": "2025-01-01"})
simple_excel.body = excel_body
simple_excel.write_sheet("sheet name")
2. 시트별로 데이터를 나누어 작성
with SimpleExcel(save_to="test") as simple_excel:
simple_excel.header = {"이름": "이름", "휴대폰": "휴 대 폰", "가입일": "가입일"}
simple_excel.cell_styles = {"휴대폰": {"num_format": "@"}}
simple_excel.cell_comments = {"휴대폰": "- 를 제거한 후 입력해주세요."}
excel_body = list()
for x in range(1, 100):
excel_body.append({"이름": f"홍길동{x}", "가입일": "2025-01-01"})
simple_excel.body = excel_body
simple_excel.write_sheet("by name")
excel_body = list()
for x in range(1, 100):
excel_body.append({"휴대폰": f"1012345{x}", "가입일": "2025-01-01"})
simple_excel.body = excel_body
simple_excel.write_sheet("by tel")
3. 버퍼에 저장
buffer = BytesIO()
with SimpleExcel(save_to=buffer) as simple_excel:
simple_excel.header = {"이름": "이름", "휴대폰": "휴 대 폰", "가입일": "가입일"}
simple_excel.cell_styles = {"휴대폰": {"num_format": "@"}}
simple_excel.cell_comments = {"휴대폰": "- 를 제거한 후 입력해주세요."}
excel_body = list()
for x in range(1, 100):
excel_body.append({"이름": f"홍길동{x}", "휴대폰": f"0101234567{x:02d}", "가입일": "2025-01-01"})
simple_excel.body = excel_body
simple_excel.write_sheet()
# 다운로드 응답
response = HttpResponse(
buffer.getvalue(),
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
response['Content-Disposition'] = 'attachment; filename="report.xlsx"'
return response
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
simple_excel-1.4.6.tar.gz
(6.6 kB
view details)
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 simple_excel-1.4.6.tar.gz.
File metadata
- Download URL: simple_excel-1.4.6.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a5de9d7ff166b145d9894156575eff8ec3d3b76ec383f3fb26bd6e7d70ddd0c
|
|
| MD5 |
61e95f4d4e4f8df9daf83941dc2147ff
|
|
| BLAKE2b-256 |
c9362715d5c9369aa8163b9ac9be4d8785ed6671d96913b6113134aa331dcf80
|
File details
Details for the file simple_excel-1.4.6-py3-none-any.whl.
File metadata
- Download URL: simple_excel-1.4.6-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9afc48fa6302cbc63c9275b41de03822d80984c41e28984d0b5dadc56fccc48
|
|
| MD5 |
2123637e8f3ed593b5dd8a06773c22f0
|
|
| BLAKE2b-256 |
344d3cb14a4ebe84105f06fd88fb1b49b84b74159416b75c95031ff62549f905
|