|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求助各位大佬 不知道为啥报错了 谢谢!
代码如下
from xlutils.copy import copy
import xlrd
import xlwt
xlsx = xlrd.open_workbook('d:/算.xlsx',formatting_info=True)
table = xlsx.sheet_by_index(0)
new_excel = copy(xlsx)
new_sheet = new_sheet.get_sheet(0)
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = '微软雅黑'
font.bold = True #加粗
font.height = 360 #字size*20
style.font =font
#边框
borders = xlwt.Borders()
borders.top = xlwt.Borders.THIN #细线框
borders.bottom = xlwt.Borders.THIN
borders.left = xlwt.Borders.THIN
borders.right = xlwt.Borders.THIN
style.borders =borders
#对齐
alignment = xlwt.Alignment()
alignment.horz = xlwt.Alignment.HORZ_CENTER
alignment.vert = xlwt.Alignment.VERT_CENTER
style.alignment = alignment
new_sheet.write(2,1,12,style)
new_sheet.write(3,1,15,style)
new_sheet.write(4,1,18,style)
new_excel.save('d:/test.xls')
报错如下
Traceback (most recent call last):
File "c:\Users\11573\python练手\复制格式.py", line 1, in <module>
from xlutils.copy import copy
ModuleNotFoundError: No module named 'xlutils'
但是我已经装了这个模块
PS C:\Users\11573\python练手> pip install xlutils
Requirement already satisfied: xlutils in c:\python38\lib\site-packages (2.0.0)
Requirement already satisfied: xlwt>=0.7.4 in c:\python38\lib\site-packages (from xlutils) (1.3.0)
Requirement already satisfied: xlrd>=0.7.2 in c:\python38\lib\site-packages (from xlutils) (1.2.0)
本帖最后由 疾风怪盗 于 2020-9-16 12:12 编辑
就刚安装的xlutils2.0.0,加python3.8.3,运行没问题
应该是你的环境配置问题,安装了几个python? 可以试着查看下pip list,或者卸载了重新安装
还有代码中有两个错了, - xlsx = xlrd.open_workbook('test.xls',formatting_info=True)
复制代码应该只能操作xls文档,不支持xlsx
- new_sheet = new_excel.get_sheet(0)
复制代码这里也写错了,应该是new_excel
然后再运行,就没问题了
|
|