openpyxl工作表命名
问题请教,小白找不到问题点了import openpyxl
wb = openpyxl.Workbook('短腿喵.xlsx')
sheet_1=wb.active
sheet_1.title = "沙丘"
wb.save('短腿喵.xlsx')
pycharm报错了
Traceback (most recent call last):
File "D:/Python_learn/apple.py", line 441, in <module>
sheet_1.title = "沙丘"
AttributeError: 'NoneType' object has no attribute 'title'
头都要炸了,这是我哪里犯错了?? 还有这个:
import openpyxl
wb = openpyxl.Workbook('沙丘.xlsx')
sheet = wb.active
# sheet.title = '短腿喵'
for line in sheet['B1':'C4']:
for cell in line:
sheet = '小兔子'
wb.save('沙丘.xlsx')
print('done!')
报错
Traceback (most recent call last):
File "D:/Python_learn/apple.py", line 425, in <module>
for line in sheet['B1':'C4']:
TypeError: 'NoneType' object is not subscriptable 本帖最后由 qq1151985918 于 2021-4-21 15:25 编辑
创建
import openpyxl
wb = openpyxl.Workbook()
sheet_1=wb.active
sheet_1.title = "沙丘"
wb.save('短腿喵.xlsx')
打开
import openpyxl
wb = openpyxl.load_workbook('短腿喵.xlsx')
sheet_1=wb.active
sheet_1.title = "沙丘2"
wb.save('短腿喵.xlsx')
基本的用法 自个去官网先看一看,OK?
https://openpyxl.readthedocs.io/en/stable/usage.html
页:
[1]