1 Star 0 Fork 0

Flon.Musk/productivity

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
excel_extract_merge.py 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
Flon.Musk 提交于 2021-08-09 00:22 . add excel_extract_merge.py.
import xlrd
import xlwt
from pathlib import Path, PurePath
'''
WARNING:
xlrd: 1.2.0 version support .xls and .xlsx, upper version only support .xls
xlwt: only support .xls
'''
src_file = 'D:/productivity/01/data'
dst_file = 'D:/productivity/01/result.xls'
# extract target data from all src xlsx files
p = Path(src_file)
files = [x for x in p.iterdir() if PurePath(x).match('*.xlsx')]
content = []
for file in files:
username = file.stem
data = xlrd.open_workbook(file)
sheet = data.sheets()[0]
answer0 = sheet.cell_value(rowx=4, colx=4) # row/col index counted from 0
answer1 = sheet.cell_value(rowx=10, colx=4)
temp = f'{username},{answer0},{answer1}'
content.append(temp.split(',')) # this temp text has changed to a list after use split()
print(temp)
# save target data as result to dst_file
sheet_header = ['name', 'question1', 'question2']
work_book = xlwt.Workbook(encoding='utf-8')
result_sheet = work_book.add_sheet('result')
row = 0
col = 0
# sheet header
for cell_header in sheet_header:
result_sheet.write(row, col, cell_header)
col += 1
# sheet result data
row += 1
for line in content:
col = 0
for cell in line:
result_sheet.write(row, col, cell)
col += 1
row += 1
work_book.save(dst_file)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/flonmusk/productivity.git
git@gitee.com:flonmusk/productivity.git
flonmusk
productivity
productivity
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385