Last modified: Nov 14, 2025 By Alexander Williams
Python openpyxl Read Only vs Normal Mode Guide
Working with Excel files in Python requires smart choices. The openpyxl library offers two main modes. Understanding read_only and normal mode is essential.
This guide covers both modes in detail. You will learn when to use each one. Performance differences and practical examples are included.
What is Normal Mode in openpyxl?
Normal mode is the default way to work with Excel files. It loads the entire workbook into memory. This gives you full access to all features.
You can read, write, and modify cells freely. Formatting and formulas are fully supported. This mode works best for smaller files.
Use normal mode when you need to make changes. It is perfect for files under 10MB. The entire file stays in RAM during processing.
# Loading workbook in normal mode
from openpyxl import load_workbook
# Default mode - loads entire file
workbook = load_workbook('example.xlsx')
sheet = workbook.active
# Read cell value
value = sheet['A1'].value
print(f"Cell A1 value: {value}")
# Modify cell
sheet['B2'] = "New Data"
# Save changes
workbook.save('modified.xlsx')
Cell A1 value: Sample Data
What is Read Only Mode?
Read only mode is optimized for large files. It loads data on demand rather than all at once. This saves significant memory.
You can only read data in this mode. Writing or modifying cells is not possible. It is perfect for data extraction tasks.
Use read_only=True for files over 10MB. Memory usage stays low regardless of file size. Processing happens in a streaming fashion.
# Loading workbook in read_only mode
from openpyxl import load_workbook
# Read only mode for large files
workbook = load_workbook('large_file.xlsx', read_only=True)
sheet = workbook.active
# Iterate through rows efficiently
for row in sheet.iter_rows(values_only=True):
print(row[0]) # Print first column value
# Close the workbook
workbook.close()
Data Row 1
Data Row 2
Data Row 3
...
Key Differences and Performance Comparison
Memory usage is the biggest difference. Normal mode loads everything into RAM. Read only mode streams data as needed.
For a 50MB Excel file, normal mode uses 50MB+ of RAM. Read only mode uses only a few MB. The difference grows with file size.
Functionality varies significantly. Normal mode supports all operations. Read only mode only allows reading.
You cannot modify cells, add formulas, or change formatting in read only mode. These operations require normal mode access.
Speed depends on your use case. Normal mode is faster for small files. Read only mode wins for large data extraction.
When to Use Each Mode
Choose normal mode for these scenarios. File modification and formatting changes. Working with small to medium files.
Creating new workbooks or templates. When you need full Excel functionality. Interactive applications with user edits.
Choose read only mode for these cases. Processing large Excel files efficiently. Data extraction and analysis tasks.
Reading files over 10MB in size. When you only need to read data. Memory-constrained environments.
Practical Examples and Use Cases
Here is a complete example showing both modes. We will process the same file differently. Each approach serves different needs.
# Example 1: Normal mode for full editing
def process_with_normal_mode(filename):
workbook = load_workbook(filename)
sheet = workbook.active
# Modify multiple cells
sheet['A1'] = "Updated Header"
sheet['B1'] = "New Column"
# Apply formatting
from openpyxl.styles import Font
sheet['A1'].font = Font(bold=True)
# Add formulas
sheet['C2'] = "=SUM(A2:B2)"
workbook.save('updated_' + filename)
print("File updated with normal mode")
# Example 2: Read only mode for data extraction
def extract_with_readonly(filename):
workbook = load_workbook(filename, read_only=True)
sheet = workbook.active
data = []
# Efficiently read all rows
for row in sheet.iter_rows(min_row=2, values_only=True):
data.append({
'name': row[0],
'value': row[1]
})
workbook.close()
print(f"Extracted {len(data)} records with read only mode")
return data
# Usage examples
process_with_normal_mode('small_data.xlsx')
extract_with_readonly('large_data.xlsx')
File updated with normal mode
Extracted 15000 records with read only mode
Advanced Read Only Techniques
Read only mode offers advanced features. You can limit which cells get loaded. This further improves performance.
Use iter_rows with specific ranges. Load only the columns you actually need. Skip header rows when appropriate.
For extremely large files, consider streaming mode. Our Python openpyxl Streaming Write Mode Guide covers this advanced topic.
# Advanced read only usage
workbook = load_workbook('huge_file.xlsx', read_only=True)
sheet = workbook.active
# Read specific range efficiently
for row in sheet.iter_rows(min_row=10, max_row=1000,
min_col=1, max_col=5,
values_only=True):
# Process only needed data
process_data(row[0], row[2], row[4])
workbook.close()
Common Pitfalls and Best Practices
Avoid mixing modes in the same session. Do not try to write to a read only workbook. This will cause errors.
Always close read only workbooks explicitly. Use workbook.close() when done. This releases file handles properly.
For formatting tasks, check our Format Excel Tables with Python openpyxl guide. It covers normal mode formatting extensively.
When working with very large datasets, see our Handle Large Excel Files Efficiently Python openpyxl article for more optimization tips.
Conclusion
Choosing between read only and normal mode is crucial. Your decision impacts performance and capabilities.
Use normal mode for editing and small files. Use read only mode for reading large files efficiently.
Both modes serve important purposes in Excel automation. Understanding when to use each will make your Python scripts more effective.
Remember the key points. Normal mode for full functionality. Read only mode for memory-efficient reading.
Choose wisely based on your specific needs. Your Excel processing tasks will run smoother and faster.