我将下面的代码编写到 excel 文件,但它有错误
"C:UsersInsiskyLeeAppDataLocalProgramsPythonPython36python.exe: can't open file 'Test': [Errno 2] No such file or directory"
如何解决?如何按特定路径保存文件?
from openpyxl import Workbook
import time
book = Workbook()
sheet = book.active
sheet['A1'] = 56
sheet['A2'] = 43
now = time.strftime("%x")
sheet['A3']=now
book.save("C:\InsiskyLeeDesktopTestWriteToExcel.xlsx")
您必须将路径放入原始字符串中,因为"\"是python尝试中的转义字符
book.save(r"C:InsiskyLeeDesktopTestWriteToExcel.xlsx")