Accelerated Excel XLSX Writing Library for Python 2/3
Project description
Accelerated Excel XLSX writing library for Python
Authors: Kevin Wang and Kevin Zhang
Copyright 2015 Kevin Wang, Kevin Zhang. Portions copyright Google, Inc.
License: Simplified BSD License
Description
PyExcelerate is a Python for writing Excel-compatible XLSX spreadsheet files, with an emphasis on speed.
Benchmarks
| TEST_NAME | NUM_ROWS | NUM_COLS | TIME_IN_SECONDS | |-----------------------------|----------|----------|-----------------| | pyexcelerate value fastest | 1000 | 100 | 0.47 | | pyexcelerate value faster | 1000 | 100 | 0.51 | | pyexcelerate value fast | 1000 | 100 | 1.53 | | xlsxwriter value | 1000 | 100 | 0.84 | | openpyxl | 1000 | 100 | 2.74 | | pyexcelerate style cheating | 1000 | 100 | 1.23 | | pyexcelerate style fastest | 1000 | 100 | 2.40 | | pyexcelerate style faster | 1000 | 100 | 2.75 | | pyexcelerate style fast | 1000 | 100 | 6.15 | | xlsxwriter style cheating | 1000 | 100 | 1.21 | | xlsxwriter style | 1000 | 100 | 4.85 | | openpyxl | 1000 | 100 | 6.32 | * cheating refers to pregeneration of styles
Installation
PyExcelerate is supported on Python 2.6, 2.7, 3.3, 3,4, and 3.5.
pip install pyexcelerate
Usage
Writing bulk data
Fastest
from pyexcelerate import Workbook
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # data is a 2D array
wb = Workbook()
wb.new_sheet("sheet name", data=data)
wb.save("output.xlsx")
Writing bulk data to a range
PyExcelerate also permits you to write data to ranges directly, which is faster than writing cell-by-cell.
Fastest
from pyexcelerate import Workbook
wb = Workbook()
ws = wb.new_sheet("test")
ws.range("B2", "C3").value = [[1, 2], [3, 4]]
wb.save("output.xlsx")
Writing cell data
Faster
from datetime import datetime
from pyexcelerate import Workbook
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws.set_cell_value(1, 1, 15) # a number
ws.set_cell_value(1, 2, 20)
ws.set_cell_value(1, 3, "=SUM(A1,B1)") # a formula
ws.set_cell_value(1, 4, datetime.now()) # a date
wb.save("output.xlsx")
Fast
from datetime import datetime
from pyexcelerate import Workbook
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws[1][1].value = 15 # a number
ws[1][2].value = 20
ws[1][3].value = "=SUM(A1,B1)" # a formula
ws[1][4].value = datetime.now() # a date
wb.save("output.xlsx")
Selecting cells by name
from pyexcelerate import Workbook
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws.cell("A1").value = 12
wb.save("output.xlsx")
Merging cells
from pyexcelerate import Workbook
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws[1][1].value = 15
ws.range("A1", "B1").merge()
wb.save("output.xlsx")
Styling cells
Styling cells causes non-negligible overhead. It will increase your execution time (up to 10x longer if done improperly!). Only style cells if absolutely necessary.
Fastest
from pyexcelerate import Workbook, Color, Style, Font, Fill, Format
from datetime import datetime
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws.set_cell_value(1, 1, 1)
ws.set_cell_style(1, 1, Style(font=Font(bold=True)))
ws.set_cell_style(1, 1, Style(font=Font(italic=True)))
ws.set_cell_style(1, 1, Style(font=Font(underline=True)))
ws.set_cell_style(1, 1, Style(font=Font(strikethrough=True)))
ws.set_cell_style(1, 1, Style(fill=Fill(background=Color(255,0,0,0))))
ws.set_cell_value(1, 2, datetime.now())
ws.set_cell_style(1, 1, Style(format=Format('mm/dd/yy')))
wb.save("output.xlsx")
Faster
from pyexcelerate import Workbook, Color
from datetime import datetime
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws.set_cell_value(1, 1, 1)
ws.get_cell_style(1, 1).font.bold = True
ws.get_cell_style(1, 1).font.italic = True
ws.get_cell_style(1, 1).font.underline = True
ws.get_cell_style(1, 1).font.strikethrough = True
ws.get_cell_style(1, 1).fill.background = Color(0, 255, 0, 0)
ws.set_cell_value(1, 2, datetime.now())
ws.get_cell_style(1, 1).format.format = 'mm/dd/yy'
wb.save("output.xlsx")
Fast
from pyexcelerate import Workbook, Color
from datetime import datetime
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws[1][1].value = 1
ws[1][1].style.font.bold = True
ws[1][1].style.font.italic = True
ws[1][1].style.font.underline = True
ws[1][1].style.font.strikethrough = True
ws[1][1].style.fill.background = Color(0, 255, 0, 0)
ws[1][2].value = datetime.now()
ws[1][2].style.format.format = 'mm/dd/yy'
wb.save("output.xlsx")
Note that .style.format.format’s repetition is due to planned support for conditional formatting and other related features. The formatting syntax may be improved in the future.
Styling ranges
from pyexcelerate import Workbook, Color
from datetime import datetime
wb = Workbook()
ws = wb.new_sheet("test")
ws.range("A1","C3").value = 1
ws.range("A1","C1").style.font.bold = True
ws.range("A2","C3").style.font.italic = True
ws.range("A3","C3").style.fill.background = Color(255, 0, 0, 0)
ws.range("C1","C3").style.font.strikethrough = True
Styling rows
A simpler (and faster) way to style an entire row.
Fastest
from pyexcelerate import Workbook, Color, Style, Fill
from datetime import datetime
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws.set_row_style(1, Style(fill=Fill(background=Color(255,0,0,0))))
wb.save("output.xlsx")
Faster
from pyexcelerate import Workbook, Color
from datetime import datetime
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws.get_row_style(1).fill.background = Color(255, 0, 0)
wb.save("output.xlsx")
Fast
from pyexcelerate import Workbook, Color
from datetime import datetime
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws[1].style.fill.background = Color(255, 0, 0)
wb.save("output.xlsx")
Styling columns
Fastest
from pyexcelerate import Workbook, Color, Style, Fill
from datetime import datetime
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws.set_col_style(1, Style(fill=Fill(background=Color(255,0,0,0))))
wb.save("output.xlsx")
Available style attributes
Consistent with the implementation patterns above, the following style parameters are available:
ws[1][1].style.font.bold = True ws[1][1].style.font.italic = True ws[1][1].style.font.underline = True ws[1][1].style.font.strikethrough = True ws[1][1].style.font.color = Color(255, 0, 255) ws[1][1].style.fill.background = Color(0, 255, 0) ws[1][1].style.alignment.vertical = 'top' ws[1][1].style.alignment.horizontal = 'right' ws[1][1].style.alignment.rotation = 90 ws[1][1].style.alignment.wrap_text = True ws[1][1].style.borders.top.color = Color(255, 0, 0) ws[1][1].style.borders.right.style = '-.'
Each attribute also has constructors for implementing via set_cell_style().
The following border styles are available: .-, ..-, --, .., =, ., medium -., medium -.., medium --, /-., _
Setting row heights and column widths
Row heights and column widths are set using the size attribute in Style. Appropriate values are: * -1 for auto-fit * 0 for hidden * Any other value for the appropriate size.
For example, to hide column B:
from pyexcelerate import Workbook, Color, Style, Fill
from datetime import datetime
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws.set_col_style(2, Style(size=0))
wb.save("output.xlsx")
Linked styles
PyExcelerate supports using style objects instead manually setting each attribute as well. This permits you to modify the style at a later time.
from pyexcelerate import Workbook, Font
wb = Workbook()
ws = wb.new_sheet("sheet name")
ws[1][1].value = 1
font = Font(bold=True, italic=True, underline=True, strikethrough=True)
ws[1][1].style.font = font
wb.save("output.xlsx")
Packaging with PyInstaller
PyInstaller is the only packager officially supported by PyExcelerate. Copy hook-pyexcelerate.Writer.py to your PyInstaller hooks directory.
Support
Please use the GitHub Issue Tracker and pull request system to report bugs/issues and submit improvements/changes, respectively. Pull requests *must* be based against the dev branch - if not, we will reject the PR and ask you to rebase against the correct branch. All nontrivial changes to code should be accompanied by a test when appropriate. We use the Nose testing framework.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyexcelerate-0.13.0.tar.gz.
File metadata
- Download URL: pyexcelerate-0.13.0.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3d20c9aa3cf6685603efa16259d44a18165f3544597cb8cb2b486c58ca14b37
|
|
| MD5 |
ab90a9ac0c6a97574fd000418c67f24a
|
|
| BLAKE2b-256 |
fb4984f7812fb47ebe6b16cc4b36759576d99f8779affe37753cdd59b0c9bcf9
|
Provenance
The following attestation bundles were made for pyexcelerate-0.13.0.tar.gz:
Publisher:
publish.yml on kz26/PyExcelerate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyexcelerate-0.13.0.tar.gz -
Subject digest:
a3d20c9aa3cf6685603efa16259d44a18165f3544597cb8cb2b486c58ca14b37 - Sigstore transparency entry: 219303152
- Sigstore integration time:
-
Permalink:
kz26/PyExcelerate@c088ab2c19914a80c02fa94383475c489186c691 -
Branch / Tag:
refs/tags/0.13.0 - Owner: https://github.com/kz26
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c088ab2c19914a80c02fa94383475c489186c691 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyexcelerate-0.13.0-py3-none-any.whl.
File metadata
- Download URL: pyexcelerate-0.13.0-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c78be1d45a35e1b3db75d1d229b7fd36a76829a8dda05b66336cd1b46565634b
|
|
| MD5 |
61e4c6090bac8795854211c161d0e20f
|
|
| BLAKE2b-256 |
6af8ee05eeb3b865f3bb46816493e89289acbe48f2b3cb9f81fef78862c97ea7
|
Provenance
The following attestation bundles were made for pyexcelerate-0.13.0-py3-none-any.whl:
Publisher:
publish.yml on kz26/PyExcelerate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyexcelerate-0.13.0-py3-none-any.whl -
Subject digest:
c78be1d45a35e1b3db75d1d229b7fd36a76829a8dda05b66336cd1b46565634b - Sigstore transparency entry: 219303157
- Sigstore integration time:
-
Permalink:
kz26/PyExcelerate@c088ab2c19914a80c02fa94383475c489186c691 -
Branch / Tag:
refs/tags/0.13.0 - Owner: https://github.com/kz26
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c088ab2c19914a80c02fa94383475c489186c691 -
Trigger Event:
push
-
Statement type: