老师,这个报错误不理解,我已经把文件改成xls后缀了
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2022/3/22 23:53
# @Author : 人间有味是清欢
# @File : 03_open_excle.py
# @Software: PyCharm
# pip install xlutils
from xlutils.copy import copy
import xlrd
# 打开excle
read_book = xlrd.open_workbook('电影数据.xls')
# 复制表
wb = copy(read_book)
# 选择表
sh_cp = wb.get_sheet(0)
# sh_cp = wb.sheet_by_index(0)
sh_cp.write(5, 0, '我们的校园')
sh_cp.write(5, 1, '89000')
sh_cp.write(5, 1, '8.2')
sh_cp.write(5, 1, '1')
# 添加新表
sh_cp2 = wb.add_sheet('汇总')
# 初始化汇总
# print(sh_cp.nrows)
rs = read_book.sheet_by_index(0)
count = 0
for j in range(1, rs.nrows):
for i in range(1, rs.ncols):
# print(type(count))
print(type(rs.cell_value(j, i)))
print(type(int(rs.cell_value(j, i))))
count += int(rs.cell_value(j, i))
# 调取原数据字段
sh_cp2.write(0, j, f'{rs.cell(0, j - 1)}')
sh_cp2.write(1, j, count)
sh_cp2.save('数据汇总.xlsx')
