Python | Writing to an excel file using openpyxl module Last Updated : 03 May, 2018 Comments Improve Suggest changes Like Article Like Report Prerequisite : Reading an excel file using openpyxl Openpyxl is a Python library for reading and writing Excel (with extension xlsx/xlsm/xltx/xltm) files. The openpyxl module allows Python program to read and modify Excel files. For example, user might have to go through thousands of rows and pick out few handful information to make small changes based on some criteria. Using Openpyxl module, these tasks can be done very efficiently and easily. Let’s see how to create and write to an excel-sheet using Python. Code #1 : Program to print a active sheet title name Python3 # import openpyxl module import openpyxl # Call a Workbook() function of openpyxl # to create a new blank Workbook object wb = openpyxl.Workbook() # Get workbook active sheet # from the active attribute. sheet = wb.active # Once have the Worksheet object, # one can get its name from the # title attribute. sheet_title = sheet.title print("active sheet title: " + sheet_title) Output : active sheet title: Sheet Code #2 : Program to change the Title name Python3 # import openpyxl module import openpyxl # Call a Workbook() function of openpyxl # to create a new blank Workbook object wb = openpyxl.Workbook() # Get workbook active sheet # from the active attribute sheet = wb.active # One can change the name of the title sheet.title = "sheet1" print("sheet name is renamed as: " + sheet.title) Output : sheet name is renamed as: sheet1 Code #3 :Program to write to an Excel sheet Python3 # import openpyxl module import openpyxl # Call a Workbook() function of openpyxl # to create a new blank Workbook object wb = openpyxl.Workbook() # Get workbook active sheet # from the active attribute sheet = wb.active # Cell objects also have row, column # and coordinate attributes that provide # location information for the cell. # Note: The first row or column integer # is 1, not 0. Cell object is created by # using sheet object's cell() method. c1 = sheet.cell(row = 1, column = 1) # writing values to cells c1.value = "ANKIT" c2 = sheet.cell(row= 1 , column = 2) c2.value = "RAI" # Once have a Worksheet object, one can # access a cell object by its name also. # A2 means column = 1 & row = 2. c3 = sheet['A2'] c3.value = "RAHUL" # B2 means column = 2 & row = 2. c4 = sheet['B2'] c4.value = "RAI" # Anytime you modify the Workbook object # or its sheets and cells, the spreadsheet # file will not be saved until you call # the save() workbook method. wb.save("C:\\Users\\user\\Desktop\\demo.xlsx") Output : code #4 :Program to add Sheets in the Workbook Python3 # import openpyxl module import openpyxl # Call a Workbook() function of openpyxl # to create a new blank Workbook object wb = openpyxl.Workbook() sheet = wb.active # Sheets can be added to workbook with the # workbook object's create_sheet() method. wb.create_sheet(index = 1 , title = "demo sheet2") wb.save("C:\\Users\\user\\Desktop\\demo.xlsx") Output : Comment More infoAdvertise with us Next Article Python | Writing to an excel file using openpyxl module ankthon Follow Improve Article Tags : Python python-modules Practice Tags : python Similar Reads Reading an excel file using Python openpyxl module Openpyxl is a Python library for reading and writing Excel (with extension xlsx/xlsm/xltx/xltm) files. The Openpyxl Module allows Python programs to read and modify Excel files. For example, users might have to go through thousands of rows and pick out a few handfuls of information to make small cha 3 min read Create and Write on Excel File using xlsxwriter Module - Python XlsxWriter The xlsxwriter module in Python is used to create Excel .xlsx files and write data into them. It supports:Writing text, numbers, and formulasCreating multiple worksheetsFormatting, charts, images, filters, and conditional formattingInstallationBefore using xlsxwriter, we need to install i 2 min read Writing to an excel sheet using Python Using xlwt module, one can perform multiple operations on spreadsheet. For example, writing or modifying the data can be done in Python. Also, the user might have to go through various sheets and retrieve data based on some criteria or modify some rows and columns and do a lot of work. Let's see how 2 min read Python | Adjusting rows and columns of an excel file using openpyxl module Prerequisites : Excel file using openpyxl writing | reading Set the height and width of the cells:Worksheet objects have row_dimensions and column_dimensions attributes that control row heights and column widths. A sheetâs row_dimensions and column_dimensions are dictionary-like values; row_dimensio 3 min read Merge and Unmerge Excel Cells using openpyxl in Python In this article, we are going to learn about Python programs to merge and unmerge excel cells using openpyxl.IntroductionOpenpyxl is a Python library commonly used for reading and writing Excel Files. In this article, we will be using this library to merge cells in Excel. Merging is helpful when we 4 min read How to import an excel file into Python using Pandas? It is not always possible to get the dataset in CSV format. So, Pandas provides us the functions to convert datasets in other formats to the Data frame. An excel file has a '.xlsx' format. Before we get started,  we need to install a few libraries. pip install pandas pip install xlrd  For importin 2 min read Python | Plotting Line charts in excel sheet using XlsxWriter module Prerequisite: Create and Write on an excel sheet XlsxWriter is a Python library using which one can perform multiple operations on excel files like creating, writing, arithmetic operations and plotting graphs. Letâs see how to plot Line charts using realtime data. Charts are composed of at least one 3 min read Python | Plotting Pie charts in excel sheet using XlsxWriter module Prerequisite: Create and Write on an excel sheet XlsxWriter is a Python library using which one can perform multiple operations on excel files like creating, writing, arithmetic operations and plotting graphs. Letâs see how to plot different types of pie charts using realtime data. Charts are compos 5 min read Python | Plotting charts in excel sheet using openpyxl module | Set - 1 Prerequisite: Reading & Writing to excel sheet using openpyxl Openpyxl is a Python library using which one can perform multiple operations on excel files like reading, writing, arithmetic operations and plotting graphs. Let's see how to plot different charts using realtime data. Charts are compo 6 min read Python | Plotting charts in excel sheet using openpyxl module | Set â 2 Prerequisite: Python | Plotting charts in excel sheet using openpyxl module | Set â 1 Openpyxl is a Python library using which one can perform multiple operations on excel files like reading, writing, arithmetic operations and plotting graphs. Charts are composed of at least one series of one or mor 6 min read Like