没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论

Docs » openpyxl 2.4.2 documentation
openpyxl - A Python library to read/write Excel
2010 xlsx/xlsm files
Author:
Eric Gazoni, Charlie Clark
Source code:
http://bitbucket.org/openpyxl/openpyxl/src
Issues:
http://bitbucket.org/openpyxl/openpyxl/issues
Generated:
February 13, 2017
License:
MIT/Expat
Version:
2.4.2
Introduction
Openpyxl is a Python library for reading and writing Excel 2010 xlsx/xlsm/xltx/xltm files.
It was born from lack of existing library to read/write natively from Python the Office Open XML
format.
All kudos to the PHPExcel team as openpyxl was initially based on PHPExcel.
Support
This is an open source project, maintained by volunteers in their spare time. This may well mean
that particular features or functions that you would like are missing. But things don’t have to
stay that way. You can contribute the project
Development
yourself or contract a developer for
particular features.
Professional support for openpyxl is available from Clark Consulting & Research and Adimian.
Donations to the project to support further development and maintenance are welcome.
Bug reports and feature requests should be submitted using the issue tracker. Please provide a
full traceback of any error you see and if possible a sample file. If for reasons of confidentiality
you are unable to make a file publicly available then contact of one the developers.
Sample code:

fromopenpyxlimportWorkbook
wb=Workbook()
#grabtheactiveworksheet
ws=wb.active
#Datacanbeassigneddirectlytocells
ws['A1']=42
#Rowscanalsobeappended
ws.append([1,2,3])
#Pythontypeswillautomaticallybeconverted
importdatetime
ws['A2']=datetime.datetime.now()
#Savethefile
wb.save("sample.xlsx")
User List
Official user list can be found on http://groups.google.com/group/openpyxl-users
How to Contribute Code
Any help will be greatly appreciated, just follow those steps:
1. Please start a new fork (https://bitbucket.org/openpyxl/openpyxl/fork) for each
independent feature, don’t try to fix all problems at the same time, it’s easier for those who
will review and merge your changes ;-)
2. Hack hack hack
3. Don’t forget to add unit tests for your changes! (YES, even if it’s a one-liner, changes
without tests will not be accepted.) There are plenty of examples in the source if you lack
know-how or inspiration.
4. If you added a whole new feature, or just improved something, you can be proud of it, so
add yourself to the AUTHORS file :-)
5. Let people know about the shiny thing you just implemented, update the docs!
6. When it’s done, just issue a pull request (click on the large “pull request” button on
your
repository) and wait for your code to be reviewed, and, if you followed all theses steps,
merged into the main repository.
For further information see
Development

Other ways to help
There are several ways to contribute, even if you can’t code (or can’t code well):
triaging bugs on the bug tracker: closing bugs that have already been closed, are not
relevant, cannot be reproduced, ...
updating documentation in virtually every area: many large features have been added
(mainly about charts and images at the moment) but without any documentation, it’s
pretty hard to do anything with it
proposing compatibility fixes for different versions of Python: we support 2.6 to 3.5, so if
it does not work on your environment, let us know :-)
Installation
Install openpyxl using pip. It is advisable to do this in a Python virtualenv without system
packages:
$pipinstallopenpyxl
Note
There is support for the popular lxml library which will be used if it is installed. This is
particular useful when creating large files.
Warning
To be able to include images (jpeg, png, bmp,...) into an openpyxl file, you will also need the
“pillow” library that can be installed with:
$pipinstallpillow
or browse https://pypi.python.org/pypi/Pillow/, pick the latest version and head to the
bottom of the page for Windows binaries.
Working with a checkout
Sometimes you might want to work with the checkout of a particular version. This may be the
case if bugs have been fixed but a release has not yet been made.
$ pip install -e hg+https://bitbucket.org/openpyxl/openpyxl@2.4#egg=openpyxl

Usage examples
Tutorial
Manipulating a workbook in memory
Create a workbook
There is no need to create a file on the filesystem to get started with openpyxl. Just import the
Workbook class and start using it
>>>fromopenpyxlimportWorkbook
>>>wb=Workbook()
A workbook is always created with at least one worksheet. You can get it by using the
openpyxl.workbook.Workbook.active() property
>>>ws=wb.active
Note
This function uses the
_active_sheet_index
property, set to 0 by default. Unless you modify its
value, you will always get the first worksheet by using this method.
You can also create new worksheets by using the openpyxl.workbook.Workbook.create_sheet()
method
>>>ws1=wb.create_sheet("Mysheet")#insertattheend(default)
#or
>>>ws2=wb.create_sheet("Mysheet",0)#insertatfirstposition
Sheets are given a name automatically when they are created. They are numbered in sequence
(Sheet, Sheet1, Sheet2, ...). You can change this name at any time with the
title
property:
ws.title="NewTitle"
The background color of the tab holding this title is white by default. You can change this
providing an RRGGBB color code to the sheet_properties.tabColor property:

ws.sheet_properties.tabColor="1072BA"
Once you gave a worksheet a name, you can get it as a key of the workbook:
>>>ws3=wb["NewTitle"]
You can review the names of all worksheets of the workbook with the
openpyxl.workbook.Workbook.sheetnames() property
>>>print(wb.sheetnames)
['Sheet2','NewTitle','Sheet1']
You can loop through worksheets
>>>forsheetinwb:
...print(sheet.title)
You can create copies of worksheets within a single workbook:
openpyxl.workbook.Workbook.copy_worksheet() method:
>>>source=wb.active
>>>target=wb.copy_worksheet(source)
Note
Only cells and styles can be copied. You cannot copy worksheets between workbooks.
You can copy worksheets in a workbook with the
Playing with data
Accessing one cell
Now we know how to access a worksheet, we can start modifying cells content.
Cells can be accessed directly as keys of the worksheet
剩余351页未读,继续阅读
















资源评论

- weixin_386696282020-05-08谢谢分享了,很高清完整的,实用
- weixin_421454122018-05-15太实用了,赞一个
dolleh
- 粉丝: 0
- 资源: 1

上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
已下载
下载帮助

看过该资源的人还看了
安全验证
文档复制为VIP权益,开通VIP直接复制
