python将数据写入EXCEL出错
fromopenpyxlimportWorkbookfromopenpyxlimportload_workbookfromopenpyxl.writer.excelimp...
from openpyxl import Workbook
from openpyxl import load_workbook
from openpyxl.writer.excel import Excelwriter
wb=wordbook()
ws=wb.active
ws.cell(1.1).value='hello excel'
for i in range(2,5);
for j in range(2,6);
ws.cell(i+1,j+1).value=i*j
wb.save('text.xlsx')
出错提示:
D:\Python\pycharm\excel\venv\Scripts\python.exe D:/Python/pycharm/excel/openexcel.py
File "D:/Python/pycharm/excel/openexcel.py", line 7
for i in range(2,5);
^
SyntaxError: invalid syntax
Process finished with exit code 1 展开
from openpyxl import load_workbook
from openpyxl.writer.excel import Excelwriter
wb=wordbook()
ws=wb.active
ws.cell(1.1).value='hello excel'
for i in range(2,5);
for j in range(2,6);
ws.cell(i+1,j+1).value=i*j
wb.save('text.xlsx')
出错提示:
D:\Python\pycharm\excel\venv\Scripts\python.exe D:/Python/pycharm/excel/openexcel.py
File "D:/Python/pycharm/excel/openexcel.py", line 7
for i in range(2,5);
^
SyntaxError: invalid syntax
Process finished with exit code 1 展开
1个回答
展开全部
from openpyxl import Workbook
from openpyxl import load_workbook
from openpyxl.writer.excel import Excelwriter
wb=wordbook()
ws=wb.active
ws.cell(1.1).value='hello excel'
for i in range(2,5):
for j in range(2,6):
ws.cell(i+1,j+1).value=i*j
wb.save('text.xlsx')
看报错是缩进导致的的,python是强制缩进的,缩进是代码的一部分
python里面的缩进,相当于C语言的里面的花括号。
另外还一个问题就是结尾的分号;应该是冒号:,具体参见上面的代码
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |