ItSolutionStuff.com

Python Xlsxwriter Create Excel File with Multiple Sheets

By Hardik Savani β€’ October 30, 2023
Python

Hi Artisan,

In this comprehensive tutorial, we will learn python xlsxwriter create excel file with multiple sheets. This post will give you a simple example of xlsxwriter create excel file with multiple sheets. I explained simply about xlsxwriter write to multiple excel sheets. I explained simply about python xlsxwriter create excel file with multiple sheets. Alright, letÒ€ℒs dive into the steps.

Xlsxwriter is a Python module that is used to write to an Excel file. Xlsxwriter is used to write text, numbers, formulas and hyperlinks to multiple worksheets etc. We can work with Workbook using Python Xlsxwriter.

In this example, we will create excel file with SheetOne and SheetTwo multiple sheet. so let's see the below examples.

You can use these examples with python3 (Python 3) version.

If you haven't install xlsxwriter in your system then you can install using the below command:

pip install xlsxwriter

Example:

main.py

import xlsxwriter
  
# Cretae a xlsx file
xlsxFile = xlsxwriter.Workbook('demo.xlsx')
  
# Add new worksheet
sheetOne = xlsxFile.add_worksheet("SheetOne")
sheetTwo = xlsxFile.add_worksheet("SheetTwo")
  
# Create List for write data into xlsx file
data = [
    { "ID": 1, "Name": "Hardik Savani", "Email": "hardik@gmail.com"},
    { "ID": 2, "Name": "Vimal Kashiyani", "Email": "vimal@gmail.com"},
    { "ID": 3, "Name": "Harshad Pathak", "Email": "harshad@gmail.com"}
]
  
row = 1
column = 0
  
# Set Header for xlsx file(SheetONE)
sheetOne.write(0, 0, "ID")
sheetOne.write(0, 1, "Name")
sheetOne.write(0, 2, "Email")
  
# Set Header for xlsx file(SheetTwo)
sheetTwo.write(0, 0, "ID")
sheetTwo.write(0, 1, "Name")
sheetTwo.write(0, 2, "Email")
  
# write into the worksheet
for item in data :
   
    # write operation perform(SheetOne)
    sheetOne.write(row, 0, item["ID"])
    sheetOne.write(row, 1, item["Name"])
    sheetOne.write(row, 2, item["Email"])
  
    # write operation perform(SheetTwo)
    sheetTwo.write(row, 0, item["ID"])
    sheetTwo.write(row, 1, item["Name"])
    sheetTwo.write(row, 2, item["Email"])
   
    # incrementing the value of row by one
    row += 1
  
# Close the Excel file
xlsxFile.close()

Output:

Now, It will generated demo.xlsx file in your root path with the below content.

demo.xlsx

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

Python Openpyxl Create Excel File with Multiple Sheets

Read Now β†’
β˜…

Python Openpyxl Create Excel File Example

Read Now β†’
β˜…

Python Pandas Create Excel File with Multiple Sheets

Read Now β†’
β˜…

Python Pandas Create Excel File Example

Read Now β†’
β˜…

How to Create and Write Xlsx File in Python?

Read Now β†’
β˜…

How to Create Excel File in Python?

Read Now β†’
β˜…

Python Read Excel File using Pandas Example

Read Now β†’
β˜…

How to Open and Read Xlsx File in Python?

Read Now β†’
β˜…

How to Read Excel File in Python?

Read Now β†’
β˜…

Python Read and Write a JSON File Example

Read Now β†’
β˜…

Python Read CSV File Specific Column Example

Read Now β†’
β˜…

Python Read CSV File Line by Line Example

Read Now β†’
β˜…

Python Write CSV File from List Example

Read Now β†’
β˜…

Python Create Zip Archive from Directory Example

Read Now β†’