Python 3 Script to Write Excel File Using xlwt Module Full Project For Beginners
Welcome folks today in this post we will be writing excel file
using xlwt module. All the source code of the application is given below.
Installation
In order to install xlwt
module we need to install by pip command
pip install xlwt
Now make a app.py
file and copy paste the following code
app.py
# 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')
Changing Fonts
# importing xlwt module
import xlwt
workbook = xlwt.Workbook()
sheet = workbook.add_sheet("Sheet Name")
# Specifying style
style = xlwt.easyxf('font: bold 1')
# Specifying column
sheet.write(0, 0, 'SAMPLE', style)
workbook.save("sample.xls")
Changing Color of Cells
# importing xlwt module
import xlwt
workbook = xlwt.Workbook()
sheet = workbook.add_sheet("Sheet Name")
# Applying multiple styles
style = xlwt.easyxf('font: bold 1, color red;')
# Writing on specified sheet
sheet.write(0, 0, 'SAMPLE', style)
workbook.save("sample.xls")