Here's some sample code I used recently to do just that.

It opens a workbook, goes down the rows, if a condition is met it writes some data in the row. Finally it saves the modified file.

from xlutils.copy import copy # http://pypi.python.org/pypi/xlutils
from xlrd import open_workbook # http://pypi.python.org/pypi/xlrd

START_ROW = 297 # 0 based (subtract 1 from excel row number)
col_age_november = 1
col_summer1 = 2
col_fall1 = 3

rb = open_workbook(file_path,formatting_info=True)
r_sheet = rb.sheet_by_index(0) # read only copy to introspect the file
wb = copy(rb) # a writable copy (I can't read values out of this, only write to it)
w_sheet = wb.get_sheet(0) # the sheet to write to within the writable copy

for row_index in range(START_ROW, r_sheet.nrows):
    age_nov = r_sheet.cell(row_index, col_age_november).value
    if age_nov == 3:
        #If 3, then Combo I 3-4 year old  for both summer1 and fall1
        w_sheet.write(row_index, col_summer1, 'Combo I 3-4 year old')
        w_sheet.write(row_index, col_fall1, 'Combo I 3-4 year old')

wb.save(file_path + '.out' + os.path.splitext(file_path)[-1])
Answer from Greg on Stack Overflow
🌐
PyPI
pypi.org › project › xlwt
xlwt · PyPI
import xlwt from datetime import datetime style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00') style1 = xlwt.easyxf(num_format_str='D-MMM-YY') wb = xlwt.Workbook() ws = wb.add_sheet('A Test Sheet') ws.write(0, 0, 1234.56, style0) ws.write(1, 0, datetime.now(), style1) ws.write(2, 0, 1) ws.write(2, 1, 1) ws.write(2, 2, xlwt.Formula("A3+B3")) wb.save('example.xls') Documentation can be found in the docs directory of the xlwt package.
Discussions

python 3.x - How do I write to an existing excel file using xlwt and keep the formatting? - Stack Overflow
I am trying to change a number in an excel file (and eventually multiple excel files by putting it in a loop). I want to edit the file and save it as a new file, which I have done successfully. The More on stackoverflow.com
🌐 stackoverflow.com
python - xlwt write excel sheet on the fly - Stack Overflow
It can also be a stream object with a write method, such as a StringIO, in which case the data for the excel file is written to the stream. ... from io import StringIO # instead of Python 2.x `import StringIO` f = StringIO() # create a file-like object wbk = xlwt.Workbook() earnings_tab = ... More on stackoverflow.com
🌐 stackoverflow.com
xlw - python xlwt, write to the next available line - Stack Overflow
I know you can do this sheet1.write(3, 3, 'TEXT') Or you can do a for loop, but I have multiple users working with my file and I don't know what's the number of the current row. I could create a ... More on stackoverflow.com
🌐 stackoverflow.com
August 20, 2018
python - Writing multi-line strings to cells using xlwt module - Stack Overflow
Python: Is there a way to write multi-line strings into an excel cell with just the xlwt module? (I saw answers suggesting use of openpyxl module) The sheet.write() method ignores the \n escape More on stackoverflow.com
🌐 stackoverflow.com
July 4, 2019
People also ask

Should I still use xlwt to write Excel files?
No. xlwt only writes the legacy .xls (BIFF) format - it cannot create modern .xlsx files - and the project is effectively unmaintained. For new code, use openpyxl or XlsxWriter to write .xlsx. The only situation where xlwt is justified is maintaining an old system that specifically requires the binary .xls format.
🌐
micropyramid.com
micropyramid.com › home › blog › python › generate csv & excel files in python: csv, openpyxl & xlsxwriter
Using Python Xlwt Generating CSV Writer and Excel Files
openpyxl vs XlsxWriter - which should I choose?
Use openpyxl when you need to read or edit existing .xlsx files as well as create them - it round-trips workbooks. Use XlsxWriter when you are only creating new files and want the richest formatting, conditional formatting, images, and native charts, plus faster writes and a constant-memory mode for huge files. XlsxWriter cannot open existing workbooks; openpyxl can. Many teams use openpyxl to read inputs and XlsxWriter to generate polished outputs. If your data is already in a pandas DataFrame, df.to_excel(engine="openpyxl") or engine="xlsxwriter" wraps either one for you.
🌐
micropyramid.com
micropyramid.com › home › blog › python › generate csv & excel files in python: csv, openpyxl & xlsxwriter
Using Python Xlwt Generating CSV Writer and Excel Files
How do I make Excel open my CSV with the correct accented characters?
Write the file with encoding="utf-8-sig" instead of plain "utf-8". The -sig variant prepends a UTF-8 byte-order mark (BOM), which is the signal Excel on Windows uses to detect UTF-8. Without it, Excel may guess the wrong encoding and turn accented or non-Latin characters into garbled text.
🌐
micropyramid.com
micropyramid.com › home › blog › python › generate csv & excel files in python: csv, openpyxl & xlsxwriter
Using Python Xlwt Generating CSV Writer and Excel Files
🌐
Readthedocs
xlwt.readthedocs.io › en › latest › api.html
API Reference — xlwt 1.3.0 documentation
class xlwt.Worksheet.Worksheet(sheetname, parent_book, cell_overwrite_ok=False)¶ · This is a class representing the contents of a sheet in a workbook. ... You don’t normally create instances of this class yourself. They are returned from calls to add_sheet(). write(r, c, label='', ...
🌐
Toricode
toricode.com › python-write-excel-file-using-xlwt
Python Write Excel File using xlwt - Tori Code
sheet.write(0, 0, 'Name', header_style) sheet.write(0, 1, 'Email', header_style) sheet.write(1, 0, 'Julie Scott') sheet.write(1, 1, 'julie@toricode.com') sheet.write(2, 0, 'Harry Hernandez') sheet.write(2, 1, 'harry@toricode.com') ... import xlwt workbook = xlwt.Workbook() sheet = workbook.add_sheet("contacts") header_font = xlwt.Font() header_font.name = 'Arial' header_font.bold = True header_style = xlwt.XFStyle() header_style.font = header_font sheet.write(0, 0, 'Name', header_style) sheet.write(0, 1, 'Email', header_style) sheet.write(1, 0, 'Julie Scott') sheet.write(1, 1, 'julie@toricode.com') sheet.write(2, 0, 'Harry Hernandez') sheet.write(2, 1, 'harry@toricode.com') workbook.save('contacts.xls')
🌐
Python Excels
pythonexcels.com › python › 2009 › 09 › 10 › Using-XLWT-to-Write-Spreadsheets-Without-Excel.html
Using XLWT to Write Spreadsheets Without Excel | Python Excels
September 10, 2009 - import sys import re from xlwt import Workbook, easyxf def doxl(): '''Read raw account number and name strings, separate the data and write to an excel spreadsheet.
🌐
Worldviz
docs.worldviz.com › vizard › latest › addons_excel.htm
xlrd and xlwt
With the xlrd and xlwt Python Addon libraries you can easily read and write directly to Excel files (.xls) from Vizard.
Find elsewhere
🌐
TL Dev Tech
tldevtech.com › home › tips › write to excel file with python xlwt
Write to Excel File with Python xlwt | TL Dev Tech
August 24, 2024 - import xlwt from datetime import datetime text_style = xlwt.easyxf('font: name Times New Roman, height 200,bold True') number_style = xlwt.easyxf(num_format_str='#,##0.00') date_style = xlwt.easyxf(num_format_str='D-MMM-YY') workbook = xlwt.Workbook() worksheet = workbook.add_sheet('My First Sheet') worksheet.write_merge(0, 0, 1, 2, 'This is a merged cell', text_style) worksheet.write(1, 0, datetime.now(), date_style) worksheet.write(2, 0, 100) worksheet.write(2, 1, 200) worksheet.write(2, 2, xlwt.Formula("A3+B3")) workbook.save('excel.xls')
Top answer
1 of 1
2

You probably can't. Microsoft created xlsx files for a reason: the classic xls format is a legacy binary file piling up hundreds, maybe thousands, of features, each reprented in differing ways (and the file format was not even openly documented back then, I don't know if it is now). So there is one app that can open a xls file and guarrantee to present what is there with all the features intended by the file creator: Excel. And the same Excel version that created the file, in that.

So, any open library that can write to xls will create the most basic files, with no formatting - and be lucky if it can parse out the content parts.

xlsx files on the other hand use conforming xml files internally, and even a program that does not care to know about the full specs can change information in the file and preserve formatting and other things simply by not touching anything it does not know about, and assembling a valid xml again.

That said, if you can't convert to xlsx, maybe the easier thing to do is use Python to drive Excel itself to make the changes for you, in an automated way. The documentation for that is few and far apart, but that is possible by using pywin32 and the "COM" api - take a look here for a start: https://pbpython.com/windows-com.html

Another option is using LibreOffice - it can read and write xls files with formatting (though surely with losses), and is scriptable in Python. Unfortunatelly, the information on how to script LibreOffice using Python to do that is also hard to find, and the legacy option of using their "UNO" thing to enable interaction with Python makes its use complicated.

🌐
MicroPyramid
micropyramid.com › home › blog › python › generate csv & excel files in python: csv, openpyxl & xlsxwriter
Using Python Xlwt Generating CSV Writer and Excel Files
June 10, 2026 - No. xlwt only writes the legacy .xls (BIFF) format - it cannot create modern .xlsx files - and the project is effectively unmaintained. For new code, use openpyxl or XlsxWriter to write .xlsx.
🌐
Readthedocs
xlwt.readthedocs.io
xlwt documentation — xlwt 1.3.0 documentation
xlwt documentation · Edit on GitHub · xlwt is a library for writing data and formatting information to older Excel files (ie: .xls) Documentation is sparse, please see the API reference or code for help: API Reference · Perhaps more useful is to consult the tutorial and the examples in the ...
🌐
YouTube
youtube.com › limeguru
[Live Demo] Write Excel Files In Python Using XLWT | XLWT Tutorial | Write XLS Files Using XLWT - YouTube
You will learn how to write excel files in python using XLWT and how to insert complete dataset in excel sheet.GITHUB CODE URL:https://github.com/limegurutec...
Published: June 29, 2021
Views: 1K
🌐
Medium
medium.com › @medasuryatej › working-with-excel-and-python-xlwt-92badd3116dd
Working with Excel and Python (Xlwt) | by Suryatej MSKP | Medium
May 17, 2018 - xlwt.add_palette_colour(“custom_blue_color”, 0x21) # the second argument must be a number between 8 and 64workbook.set_colour_RGB(0x21, 79, 129, 189) # Red — 79, Green — 129, Blue — 189style_blue_color = xlwt.easyxf(‘pattern: pattern solid, fore_colour custom_blue_color’)# writing data to the Zeroth Row and Zeroth Column in the excel fileworksheet.write(0, 0, “Custom Blue Color”, style_blue_color)workbook.save(“C:\\YourDirectory\\FileName.xls”) Result, Cell with Custom Blue Color (R-79,G-129, Blue-189) Wrapping and Aligning the Text (Center, Top, bottom, Left, Right) styl
🌐
GeeksforGeeks
geeksforgeeks.org › writing-excel-sheet-using-python
Writing to an excel sheet using Python - GeeksforGeeks
July 29, 2019 - # Writing to an excel # sheet using Python import xlwt from xlwt import Workbook # Workbook is created wb = Workbook() # add_sheet is used to create sheet. sheet1 = wb.add_sheet('Sheet 1') sheet1.write(1, 0, 'ISBT DEHRADUN') sheet1.write(2, 0, 'SHASTRADHARA') sheet1.write(3, 0, 'CLEMEN TOWN') sheet1.write(4, 0, 'RAJPUR ROAD') sheet1.write(5, 0, 'CLOCK TOWER') sheet1.write(0, 1, 'ISBT DEHRADUN') sheet1.write(0, 2, 'SHASTRADHARA') sheet1.write(0, 3, 'CLEMEN TOWN') sheet1.write(0, 4, 'RAJPUR ROAD') sheet1.write(0, 5, 'CLOCK TOWER') wb.save('xlwt example.xls') Output : Code #2 : Adding style sheet in excel
🌐
Stackview
stackview.dev › blog › create-excel-with-python
How to create an Excel file with Python using xlwt - StackView - StackView
October 13, 2025 - Install xlwt with the below command. ... In order to test our code after installation, we need to create a dummy data set. data = [ { "name":"Testuser1", "age":20, "country":"India" }, { "name":"Testuser2", "age":20, "country":"Canada" }, { "name":"Testuser2", "age":29, "country":"USA" }, ] Copy Code · Now we have the data to create excel file. ... for index, value in enumerate(data): sheet.write(index, 0, value["name"]) sheet.write(index, 1, value["age"]) sheet.write(index, 2, value["country"])
🌐
Python-excel
python-excel.org
Python Resources for working with Excel - Working with Excel Files in Python
This package allows you to read xlsx and xlsm files and write xlsx files. ... NB: xlwt is no longer maintained and the .xls format is largely obsolete.
🌐
Google Groups
groups.google.com › g › python-excel › c › Afo1-P_nSRY › m › Cw0tXYidbrgJ
xlwt write() using xlrd XF objects
Doing what you want to do is not possible at the moment. xlwt.filter does most of the format preservation, but it appears to be difficult/impossible to tell it that you want to insert columns, for example.
🌐
GitHub
github.com › python-excel › xlwt
GitHub - python-excel/xlwt: Library to create spreadsheet files compatible with MS Excel 97/2000/XP/2003 XLS files, on any platform. · GitHub
May 4, 2020 - import xlwt from datetime import datetime style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00') style1 = xlwt.easyxf(num_format_str='D-MMM-YY') wb = xlwt.Workbook() ws = wb.add_sheet('A Test Sheet') ws.write(0, 0, 1234.56, style0) ws.write(1, 0, datetime.now(), style1) ws.write(2, 0, 1) ws.write(2, 1, 1) ws.write(2, 2, xlwt.Formula("A3+B3")) wb.save('example.xls') Documentation can be found in the docs directory of the xlwt package.
Author: python-excel