krishna kashap
krishna kashap

Reputation: 21

unable to save workbook in xlwings

Unable to save a workbook using xlwings. Below is the code, loc contains the excel file name

import xlwings as xw
from xlwings import Book
print(xw.__version__)
app = xw.App(visible=False)
wb = Book(loc)
wb.sheets['crosst'].range('AJ2:CH9999').value=''

wb.save(loc)
app.quit()

below is the response, but when I check the Excel file, the contents are not cleared?

0.24.6

Process finished with exit code 0

Upvotes: 0

Views: 823

Answers (1)

ql.user2511
ql.user2511

Reputation: 389

Save the file under a new name, not under the same name.

import xlwings as xw
from xlwings import Book
print(xw.__version__)
app = xw.App(visible=False)
wb = Book(loc)
wb.sheets['crosst'].range('AJ2:CH9999').value=''

wb.save(loc1)
app.quit()

where loc1 is another name.

Ensure also that your cells are correct.

Upvotes: 2

Related Questions