Skip to main content

A Python library for reading and writing Excel files

Project description

pyexcelize

Introduction

Creating formatting in Python when outputting to Excel can be tedious. Usually, you will want to write the formatting in Excel and then just output the data. It is a good idea to use OpenPyXL when working with Excel in Python. However, OpenPyXL uses a very large amount of memory. OpenPyXL is not suitable for writing data to a loaded Excel. However, there is a library in the Go language called excelize that is suitable for writing data. pyexcelize wraps Go's excelize and makes it usable.

Installation

pip install pyexcelize

Basic Usage

## Create New File
index = pe.new_file()

## Save as File
pe.save_as(index, '__tmp/test.xlsx')

## Close Workbook
pe.close(index)

## Open Exist Excel file
index = pe.open_file('./__tmp/test.xlsx')

## Create New Sheet
new_sheet = pe.new_sheet(index, 'Sheet2')

## Copy New Sheet
to_sheet = pe.copy_sheet(index, 1, new_sheet)

## Set Active Sheet
pe.set_active_sheet(index, new_sheet)

## Delete Sheet
pe.delete_sheet(index, 'Sheet1')

## Set Cell Value
pe.set_cell_int(index, "Sheet2", "A1", 1)
pe.set_cell_int(index, "Sheet2", "A2", 2)
pe.set_cell_int(index, "Sheet2", "A3", 3)
pe.set_cell_str(index, "Sheet2", "A4", "hello")

## Get Cell Value
pe.get_cell_value(index, "Sheet2", "A1")
pe.get_cell_value(index, "Sheet2", "A2")
pe.get_cell_value(index, "Sheet2", "A3")
pe.get_cell_value(index, "Sheet2", "A4")

## Get Cell Style
style_index = pe.get_cell_style(index, "Sheet2", "A1")

## Copy Cell Style
pe.set_cell_style(index, "Sheet2", "A2", "A2", style_index)

## Save Update
pe.save(index)

pe.close(index)

Stream Writer with Template xlsx.
If you don't use Stream Writer, it will use more than 2GB of memory.
Stream Writer will only consume less than 100MB of memory.

index = pe.open_file('./tests/template.xlsx')
writer_index = pe.new_stream_writer(index, "Sheet1")
headers = [
    "employee name",
    "company",
    "salary",
]
pe.set_row(writer_index, "A1", headers)
for row in range(2,500000):
    params = [
        fake.name(),
        random.choice(["Google", "Microsoft", "Apple", "Toyota", "Meta"]),
        random.randint(10000, 10000000),
    ]
    pe.set_row(writer_index, f"A{row}", params)
pe.add_table(writer_index, "A1", "C499999", dict(
    table_name="テーブル1",
    table_style="TableStyleMedium2",
    show_first_column=True,
    show_last_column=True,
    show_row_stripes=True,
    show_column_stripes=False,
))
pe.flush(writer_index)
pe.save_as(index, './__tmp/output.xlsx')
pe.close(index)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyexcelize-0.2.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyexcelize-0.2.0-cp39-cp39-macosx_11_0_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

File details

Details for the file pyexcelize-0.2.0.tar.gz.

File metadata

  • Download URL: pyexcelize-0.2.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for pyexcelize-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d451f43bb12d5d3717fd0f3d91b4b27397d3e4b44fb3bbd52bc8255767d86d45
MD5 e2e4f0ea0801b136ee635ad5620297c6
BLAKE2b-256 57499f3ecd5c06147c94fe9524ec01a2161ef596859a5971e81516e605c5d2f7

See more details on using hashes here.

File details

Details for the file pyexcelize-0.2.0-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: pyexcelize-0.2.0-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: CPython 3.9, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for pyexcelize-0.2.0-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 e0eb2fcaefbaa8e9286463b38a43baedd54b7036be57873a91872f7f0c2f4828
MD5 7de60f2f5f225a67322bce74c745c74d
BLAKE2b-256 8c503a7499d9c3fd57d1ad088b312b8bea5c21e4df7afe10603bd9e798f8253a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page