0

I write the code below to excel file but It have error

"C:\Users\InsiskyLee\AppData\Local\Programs\Python\Python36\python.exe: can't open file 'Test': [Errno 2] No such file or directory"

How to fix it? How to save file by specific path?

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:\\InsiskyLee\Desktop\TestWriteToExcel.xlsx")

1 Answer 1

2

You must put the path into a raw string because "\" is the escape character in python try

book.save(r"C:\InsiskyLee\Desktop\TestWriteToExcel.xlsx")
Sign up to request clarification or add additional context in comments.

2 Comments

Still have same error : can't open file 'Test': [Errno 2] No such file or directory.
Show me how you defined the path to the file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.