Metadata-Version: 2.2
Name: excelize
Version: 0.0.3
Summary: A Python build of the Go Excelize library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
Author: xuri
Author-email: xuri.me@gmail.com
Maintainer: xuri
Maintainer-email: xuri.me@gmail.com
License: BSD 3-Clause
Project-URL: Source, https://github.com/xuri/excelize-py
Project-URL: Documentation, https://xuri.me/excelize
Keywords: excelize,excel,xlsx,xlsm,xltx,xltm,xls,spreadsheet,workbook,vba,macro
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: keywords
Dynamic: license
Dynamic: maintainer
Dynamic: maintainer-email
Dynamic: project-url
Dynamic: requires-python
Dynamic: summary

# excelize-py

<p align="center"><img width="500" src="https://github.com/xuri/excelize-py/raw/main/excelize-py.svg" alt="excelize-py logo"></p>

<p align="center">
    <a href="https://pypi.org/project/excelize"><img src="https://img.shields.io/pypi/v/excelize?color=%23007ec6" alt="Pipy version"></a>
    <a href="https://github.com/xuri/excelize-py/actions/workflows/build.yml"><img src="https://github.com/xuri/excelize-py/actions/workflows/build.yml/badge.svg" alt="Build Status"></a>
    <a href="https://codecov.io/gh/xuri/excelize-py"><img src="https://codecov.io/gh/xuri/excelize-py/branch/main/graph/badge.svg" alt="Code Coverage"></a>
    <a href="https://opensource.org/licenses/BSD-3-Clause"><img src="https://img.shields.io/badge/license-bsd-orange.svg" alt="Licenses"></a>
    <a href="https://www.paypal.com/paypalme/xuri"><img src="https://img.shields.io/badge/Donate-PayPal-green.svg" alt="Donate"></a>
</p>

Package excelize-py is a Python port of Go [Excelize](https://github.com/xuri/excelize) library, providing a set of functions that allow you to write and read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and writing spreadsheet documents generated by Microsoft Excel&trade; 2007 and later. Supports complex components by high compatibility, and provided streaming API for generating or reading data from a worksheet with huge amounts of data. This library needs Python version 3.9 or later. The full API docs can be found at [docs reference](https://xuri.me/excelize/).

## Platform Compatibility

Operating system | CPU Architecture
---|---
Windows | amd64, arm64, i686
Darwin | amd64, arm64
Linux | amd64, arm64, i686

## Basic Usage

### Installation

```bash
pip install excelize
```

### Create spreadsheet

Here is a minimal example usage that will create spreadsheet file.

```python
import excelize

f = excelize.new_file()
# Create a new sheet.
index, err = f.new_sheet("Sheet2")
if err:
    print(err)
# Set value of a cell.
f.set_cell_value("Sheet2", "A2", "Hello world.")
f.set_cell_value("Sheet1", "B2", 100)
# Set active sheet of the workbook.
f.set_active_sheet(index)
# Save spreadsheet by the given path.
err = f.save_as("Book1.xlsx")
if err:
    print(err)
err = f.close()
if err:
    print(err)
```

### Reading spreadsheet

The following constitutes the bare to read a spreadsheet document.

```python
import excelize

f, err = excelize.open_file("Book1.xlsx")
if err:
    print(err)
    exit()
# Get value from cell by given worksheet name and cell reference.
cell, err = f.get_cell_value("Sheet1", "B2")
if err:
    print(err)
print(cell)
# Get all the rows in the Sheet1.
rows, err = f.get_rows("Sheet1")
if err:
    print(err)
for row in rows:
    for cell in row:
        print(f"{cell}\t", end="")
    print()
# Close the spreadsheet.
err = f.close()
if err:
    print(err)
```

### Add chart to spreadsheet file

With Excelize chart generation and management is as easy as a few lines of code. You can build charts based on data in your worksheet or generate charts without any data in your worksheet at all.

<p align="center"><img width="650" src="./chart.png" alt="Excelize"></p>

```python
import excelize

f = excelize.new_file()
data = [
    [None, "Apple", "Orange", "Pear"],
    ["Small", 2, 3, 3],
    ["Normal", 5, 2, 4],
    ["Large", 6, 7, 8],
]
for idx, row in enumerate(data):
    cell, err = excelize.coordinates_to_cell_name(1, idx + 1, False)
    if err:
        print(err)
    err = f.set_sheet_row("Sheet1", cell, row)
    if err:
        print(err)

chart = excelize.Chart(
    type=excelize.ChartType.Col3DClustered,
    series=[
        excelize.ChartSeries(
            name="Sheet1!$A$2",
            categories="Sheet1!$B$1:$D$1",
            values="Sheet1!$B$2:$D$2",
        ),
        excelize.ChartSeries(
            name="Sheet1!$A$3",
            categories="Sheet1!$B$1:$D$1",
            values="Sheet1!$B$3:$D$3",
        ),
        excelize.ChartSeries(
            name="Sheet1!$A$4",
            categories="Sheet1!$B$1:$D$1",
            values="Sheet1!$B$4:$D$4",
        ),
    ],
    title=[excelize.RichTextRun(text="Fruit 3D Clustered Column Chart")],
)
err = f.add_chart("Sheet1", "E1", chart)
if err:
    print(err)
# Save spreadsheet by the given path.
err = f.save_as("Book1.xlsx")
if err:
    print(err)
err = f.close()
if err:
    print(err)
```

### Add picture to spreadsheet file

```python
import excelize

f, err = excelize.open_file("Book1.xlsx")
if err:
    print(err)
    exit()
# Insert a picture.
err = f.add_picture("Sheet1", "A2", "image.png", None)
if err:
    print(err)
# Insert a picture to worksheet with scaling.
err = f.add_picture("Sheet1", "D2", "image.jpg", excelize.GraphicOptions(
    scale_x=0.5,
    scale_y=0.5,
))
if err:
    print(err)
# Insert a picture offset in the cell with printing support.
err = f.add_picture("Sheet1", "H2", "image.gif", excelize.GraphicOptions(
    print_object=True,
    lock_aspect_ratio=False,
    offset_x=15,
    offset_y=10,
    locked=False,
))
if err:
    print(err)
# Save the spreadsheet with the origin path.
err = f.save()
if err:
    print(err)
# Close the spreadsheet.
err = f.close()
if err:
    print(err)
```

## Contributing

Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.

## Licenses

This program is under the terms of the BSD 3-Clause License. See [https://opensource.org/licenses/BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause).

The Excel logo is a trademark of [Microsoft Corporation](https://aka.ms/trademarks-usage). This artwork is an adaptation.

gopher.{ai,svg,png} was created by [Takuya Ueda](https://twitter.com/tenntenn). Licensed under the [Creative Commons 3.0 Attributions license](http://creativecommons.org/licenses/by/3.0/).
