Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Excelize is a Python port of Go Excelize library that allow you to write to and read from XLAM / XLSM / XLSX / XLTM / XLTX files.

License

NotificationsYou must be signed in to change notification settings

xuri/excelize-py

excelize-py logo

PyPI versionBuild StatusCode CoverageLicensesDonate

Package excelize-py is a Python port of GoExcelize 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™ 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 atdocs reference.

Platform Compatibility

Operating systemCPU Architecture
Windowsamd64, arm64, i686
Darwinamd64, arm64
Linuxamd64, arm64, i686

Basic Usage

Installation

pip install excelize

Create spreadsheet

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

importexcelizef=excelize.new_file()try:# Create a new sheet.index=f.new_sheet("Sheet2")# 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.f.save_as("Book1.xlsx")except (RuntimeError,TypeError)aserr:print(err)finally:err=f.close()iferr:print(err)

Reading spreadsheet

The following constitutes the bare to read a spreadsheet document.

importexcelizetry:f=excelize.open_file("Book1.xlsx")except (RuntimeError,TypeError)aserr:print(err)exit()try:# Get value from cell by given worksheet name and cell reference.cell=f.get_cell_value("Sheet1","B2")print(cell)# Get all the rows in the Sheet1.rows=f.get_rows("Sheet1")forrowinrows:forcellinrow:print(f"{cell}\t",end="")print()except (RuntimeError,TypeError)aserr:print(err)finally:# Close the spreadsheet.err=f.close()iferr: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.

Excelize

importexcelizef=excelize.new_file()data= [    [None,"Apple","Orange","Pear"],    ["Small",2,3,3],    ["Normal",5,2,4],    ["Large",6,7,8],]try:foridx,rowinenumerate(data):cell=excelize.coordinates_to_cell_name(1,idx+1,False)f.set_sheet_row("Sheet1",cell,row)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")],    )f.add_chart("Sheet1","E1",chart)# Save spreadsheet by the given path.f.save_as("Book1.xlsx")except (RuntimeError,TypeError)aserr:print(err)finally:err=f.close()iferr:print(err)

Add picture to spreadsheet file

importexcelizetry:f=excelize.open_file("Book1.xlsx")except (RuntimeError,TypeError)aserr:print(err)exit()try:# Insert a picture.f.add_picture("Sheet1","A2","image.png",None)# Insert a picture to worksheet with scaling.f.add_picture("Sheet1","D2","image.jpg",excelize.GraphicOptions(scale_x=0.5,scale_y=0.5,    ))# Insert a picture offset in the cell with printing support.f.add_picture("Sheet1","H2","image.gif",excelize.GraphicOptions(print_object=True,lock_aspect_ratio=False,offset_x=15,offset_y=10,locked=False,    ))# Save the spreadsheet with the origin path.f.save()except (RuntimeError,TypeError)aserr:print(err)finally:# Close the spreadsheet.err=f.close()iferr: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. Seehttps://opensource.org/licenses/BSD-3-Clause.

The Excel logo is a trademark ofMicrosoft Corporation. This artwork is an adaptation.

The Go gopher was created byRenee French. Licensed under theCreative Commons 4.0 Attributions license.

About

Excelize is a Python port of Go Excelize library that allow you to write to and read from XLAM / XLSM / XLSX / XLTM / XLTX files.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors25


[8]ページ先頭

©2009-2025 Movatter.jp