Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Xlsxwriter Not Writing Into File

import xlsxwriter

workbook = xlsxwriter.Workbook('123.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write(3, 3, 'Test')
workbook.close()

I am trying to add "Test" to an excel file using xlsxwriter. But by doing so it replaces the whole excel file with only the new added text.

It’s the same result when I write it into a new file.

save() for some reason doesn’t even get recognized (it’s white).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

AttributeError: 'Workbook' object has no attribute 'save'

>Solution :

You forgot workbook.close(), add that to the end of your program, and it should work

The syntax to close an excel file in xlsxwriter is very simple i.e

workbook_object.close()

Here workbook object is the workbook which is open and now you want to close it. Its better to save the workbook before closing it. demo.xlsx can be any file name that you want.

workbook = xlsxwriter.Workbook('demo.xlsx')

So your final code will look like this:

import xlsxwriter

workbook = xlsxwriter.Workbook('123.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write(3, 3, 'Test')
workbook = xlsxwriter.Workbook('demo.xlsx')
workbook.close()

EDIT:

Based on what you provided, your problem seems to lie with the workbook not properly closing.

import xlsxwriter

workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()


worksheet.write(3, 3, 'hope this works :)')  # Writes a string to the file



workbook.close()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading