
In today's data-driven world, Python developers frequently need to convert lists (a fundamental Python data structure) into Excel spreadsheets. Excel remains the standard for data presentation, reporting, and sharing across industries. Whether you're generating reports, preparing data for analysis, or sharing information with non-technical stakeholders, the ability to efficiently export Python lists to Excel is a valuable skill.
While lightweight libraries like pandas can handle basic exports, Spire.XLS for Python gives you full control over Excel formatting, styles, and file generation – all without requiring Microsoft Excel. In this comprehensive guide, we'll explore how to use the library to convert diverse list structures into Excel in Python, complete with detailed examples and best practices.
- Why Convert Python Lists to Excel?
- Installation Guide
- Basic – Convert a Simple Python List to Excel
- Convert Nested Lists to Excel in Python
- Convert a List of Dictionaries to Excel
- 4 Tips to Optimize Your Excel Outputs
- Conclusion
- FAQs
Why Convert Python Lists to Excel?
Lists in Python are versatile for storing structured or unstructured data, but Excel offers advantages in:
- Collaboration: Excel is universally used, and stakeholders can edit, sort, or filter data without Python knowledge.
- Reporting: Add charts, pivot tables, or summaries to Excel after export.
- Compliance: Many industries require data in Excel for audits or record-keeping.
- Visualization: Excel’s formatting tools (colors, borders, headers) make data easier to read than raw Python lists.
Whether you’re working with sales data, user records, or survey results, writing lists to Excel in Python ensures your data is accessible and professional.
Installation Guide
To get started with Spire.XLS for Python, install it using pip:
pip install Spire.XLS
The Python Excel library supports Excel formats like .xls or .xlsx and lets you customize formatting (bold headers, column widths, colors), perfect for production-ready files.
To fully experience the capabilities of Spire.XLS for Python, you can request a free 30-day trial license here.
Basic – Convert a Simple Python List to Excel
For a basic one-dimensional list, iterate through the items and write them to consecutive cells in a single column.
This code example converts a list of text strings into a single column. If you need to convert a list of numeric values, you can set their number format before saving.
from spire.xls import *
from spire.xls.common import *
# Create a Workbook object
workbook = Workbook()
# Clear the default sheets
workbook.Worksheets.Clear()
# Add a new worksheet
worksheet = workbook.Worksheets.Add("Simple List")
# Sample list
data_list = ["Alexander", "Bob", "Charlie", "Diana", "Eve"]
# Write list data to Excel cells (starting from row 1, column 1)
for index, value in enumerate(data_list):
worksheet.Range[index + 1, 1].Value = value
# Set column width for better readability
worksheet.Range[1, 1].ColumnWidth = 15
# Save the workbook
workbook.SaveToFile("SimpleListToExcel.xlsx", ExcelVersion.Version2016)
workbook.Dispose()
If you need to write the list in a single row, use the following:
for index, value in enumerate(data_list):
worksheet.Range[1, index + 1].Value = value
Output: A clean Excel file with one column of names, properly spaced.

Convert Nested Lists to Excel in Python
Nested lists (2D Lists) represent tabular data with rows and columns, making them perfect for direct conversion to Excel tables. Let’s convert a nested list of employee data (name, age, department) to an Excel table.
from spire.xls import *
from spire.xls.common import *
# Create a Workbook object
workbook = Workbook()
# Clear the default sheets
workbook.Worksheets.Clear()
# Add a new worksheet
worksheet = workbook.Worksheets.Add("Employee Data")
# Nested list (rows: [Name, Age, Department])
employee_data = [
["Name", "Age", "Department"], # Header row
["Alexander", 30, "HR"],
["Bob", 28, "Engineering"],
["Charlie", 35, "Marketing"],
["Diana", 29, "Finance"]
]
# Write nested list to Excel
for row_idx, row_data in enumerate(employee_data):
for col_idx, value in enumerate(row_data):
if isinstance(value, int):
worksheet.Range[row_idx + 1, col_idx + 1].NumberValue = value
else:
worksheet.Range[row_idx + 1, col_idx + 1].Value = value
# Format header row
worksheet.Range["A1:C1"].Style.Font.IsBold = True
worksheet.Range["A1:C1"].Style.Color = Color.get_Yellow()
# Set column widths
worksheet.Range[1, 1].ColumnWidth = 10
worksheet.Range[1, 2].ColumnWidth = 6
worksheet.Range[1, 3].ColumnWidth = 15
# Save the workbook
workbook.SaveToFile("NestedListToExcel.xlsx", ExcelVersion.Version2016)
workbook.Dispose()
Explanation:
- Nested List Structure: The first sub-list acts as headers, and subsequent sub-lists are data rows.
- 2D Loop: We use nested loops to write each row and column to Excel cells.
Output: An Excel table with bold yellow headers and correctly typed data.

To make your Excel files more professional, you can add cell borders, set conditional formatting, or apply other formatting options with Spire.XLS for Python.
Convert a List of Dictionaries to Excel
Lists of dictionaries are common in Python for storing structured data with labeled fields. This example converts a list of dictionaries (e.g., customer records) to Excel and auto-extracts headers from dictionary keys.
from spire.xls import *
from spire.xls.common import *
# Create a Workbook object
workbook = Workbook()
# Clear the default sheets
workbook.Worksheets.Clear()
# Add a new worksheet
worksheet = workbook.Worksheets.Add("Customer Data")
# List of dictionaries
customers = [
{"ID": 101, "Name": "John Doe", "Email": "john@example.com"},
{"ID": 102, "Name": "Jane Smith", "Email": "jane@example.com"},
{"ID": 103, "Name": "Mike Johnson", "Email": "mike@example.com"}
]
# Extract headers from dictionary keys
headers = list(customers[0].keys())
# Write headers to row 1
for col, header in enumerate(headers):
worksheet.Range[1, col + 1].Value = header
worksheet.Range[1, col + 1].Style.Font.IsBold = True # Bold headers
# Write data rows
for row, customer in enumerate(customers, start=2): # Start from row 2
for col, key in enumerate(headers):
value = customer[key]
if isinstance(value, (int, float)):
worksheet.Range[row, col + 1].NumberValue = value
else:
worksheet.Range[row, col + 1].Value = value
# Adjust column widths
worksheet.AutoFitColumn(2)
worksheet.AutoFitColumn(3)
# Save the file
workbook.SaveToFile("CustomerDataToExcel.xlsx", ExcelVersion.Version2016)
workbook.Dispose()
Why This Is Useful:
- Auto-Extracted Headers: Saves time. No need to retype headers like “ID” or “Email”.
- Auto-Fit Columns: Excel automatically adjusts column width to fit the longest text.
- Scalable: Works for large lists of dictionaries (e.g., 1000+ customers).
Output: Excel file with headers auto-created, data types preserved, and columns automatically sized.

4 Tips to Optimize Your Excel Outputs
- Preserve Data Types: Always use NumberValue for numbers (avoids issues with Excel calculations later).
- Auto-Fit Columns: Use worksheet.AutoFitColumn() to skip manual width adjustments.
- Name Worksheets Clearly: Instead of “Sheet1”, use names like “Q3 Sales” to make files user-friendly.
- Dispose of Workbooks: Always call workbook.Dispose() to free memory (critical for large datasets).
Conclusion
Converting lists to Excel in Python is a critical skill for data professionals, and Spire.XLS makes it easy to create polished, production-ready files. Whether you’re working with simple lists, nested data, or dictionaries, the examples above can be adapted to your needs.
For even more flexibility (e.g., adding charts or formulas), explore Spire.XLS’s documentation.
FAQs for List to Excel Conversion
Q1: How is Spire.XLS different from pandas for converting lists to Excel?
A: Pandas is great for quick, basic exports, but it lacks fine-grained control over Excel formatting. Spire.XLS is better when you need:
- Custom styles (colors, fonts, borders).
- Advanced Excel features (freeze panes, conditional formatting, charts).
- Standalone functionality (no Excel installation required).
Q2: How do I save my Excel file in different formats?
A: Use the ExcelVersion parameter in SaveToFile:
workbook.SaveToFile("output.xlsx", ExcelVersion.Version2016)
workbook.SaveToFile("output.xls", ExcelVersion.Version97to2003)
Q3: How does Spire.XLS handle different data types?
A: Spire.XLS provides specific properties for different data types:
- Use .Text for strings
- Use .NumberValue for numerical data
- Use .DateTimeValue for dates
- Use .BooleanValue for True/False values
Q4: Why clear default worksheets before adding new ones?
A: Spire.XLS for Python creates default sheets when you create a Workbook. Therefore, if you don't clear it with the Workbook.Worksheets.Clear(), your file will have extra empty sheets.
Q5: My data isn't showing correctly in Excel. What's wrong?
A: Check that you're using 1-based indexing and that your data types match the expected format. Also, verify that you're saving the file before disposing of the workbook.
