Py Excel
Py Excel
Release 0.6.0
1 Introduction 3
2 Installation 5
3 Usage 7
4 Design 9
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2 Signature functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5 Tutorial 17
5.1 Work with excel files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.2 Work with excel files in memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.3 Sheet: Data conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.4 Dot notation for data source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.5 Work with big data sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.6 Sheet: Data Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.7 Sheet: Data manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
5.8 Sheet: Data filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.9 Sheet: Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.10 Book: Sheet operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
6 Cook book 49
6.1 Recipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
6.2 Loading from other sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8 API documentation 59
8.1 API Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2 Internal API reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
i
9.3 Packaging with PyInstaller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
9.4 How to write a plugin for pyexcel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
ii
pyexcel Documentation, Release 0.6.0
Author
3. Wang
Source code http://github.com/pyexcel/pyexcel.git
Issues http://github.com/pyexcel/pyexcel/issues
License New BSD License
Development 0.6.0
Released 0.5.7
Generated Jan 11, 2018
Contents 1
pyexcel Documentation, Release 0.6.0
2 Contents
CHAPTER 1
Introduction
pyexcel provides one application programming interface to read, manipulate and write data in various excel formats.
This library makes information processing involving excel files an enjoyable task. The data in excel files can be turned
into array or dict with minimal code and vice versa. This library focuses on data processing using excel files as storage
media hence fonts, colors and charts were not and will not be considered.
The idea originated from the common usability problem: when an excel file driven web application is delivered for
non-developer users (ie: team assistant, human resource administrator etc). The fact is that not everyone knows (or
cares) about the differences between various excel formats: csv, xls, xlsx are all the same to them. Instead of training
those users about file formats, this library helps web developers to handle most of the excel file formats by providing
a common programming interface. To add a specific excel file format type to you application, all you need is to install
an extra pyexcel plugin. Hence no code changes to your application and no issues with excel file formats any more.
Looking at the community, this library and its associated ones try to become a small and easy to install alternative to
Pandas.
3
pyexcel Documentation, Release 0.6.0
4 Chapter 1. Introduction
CHAPTER 2
Installation
For individual excel file formats, please install them as you wish:
5
pyexcel Documentation, Release 0.6.0
In order to manage the list of plugins installed, you need to use pip to add or remove a plugin. When you use virtualenv,
you can have different plugins per virtual environment. In the situation where you have multiple plugins that does
the same thing in your environment, you need to tell pyexcel which plugin to use per function call. For example,
pyexcel-ods and pyexcel-odsr, and you want to get_array to use pyexcel-odsr. You need to append get_array(. . . ,
library=’pyexcel-odsr’).
For compatibility tables of pyexcel-io plugins, please click here
6 Chapter 2. Installation
CHAPTER 3
Usage
7
pyexcel Documentation, Release 0.6.0
8 Chapter 3. Usage
CHAPTER 4
Design
4.1 Introduction
This section introduces Excel data models, its representing data structures and provides an overview of formatting,
transformation, manipulation supported by pyexcel.
When dealing with excel files, pyexcel pay attention to three primary objects: cell, sheet and book.
A book contains one or more sheets and a sheet is consisted of a sheet name and a two dimensional array of cells.
Although a sheet can contain charts and a cell can have formula, styling properties, this library ignores them and only
pays attention to the data in the cell and its data type. So, in the context of this library, the definition of those three
concepts are:
A data source is a storage format of structured data. The most popular data source is an excel file. Libre Of-
fice/Microsoft Excel can easily be used to generate an excel file of your desired format. Besides a physical file,
this library recognizes three additional types of source:
1. Excel files in computer memory. For example: when a file is uploaded to a Python server for information
processing. If it is relatively small, it can be stored in memory.
2. Database tables. For example: a client would like to have a snapshot of some database table in an excel file and
asks it to be sent to him.
9
pyexcel Documentation, Release 0.6.0
3. Python structures. For example: a developer may have scraped a site and have stored data in Python array or
dictionary. He may want to save this information as a file.
Reading from - and writing to - a data source is modelled as parsers and renderers in pyexcel. Excel data sources and
database sources support read and write. Other data sources may only support read only, or write only methods.
Here is a list of data sources:
This library and its plugins support most of the frequently used excel file formats.
Often a developer would like to have excel data imported into a Python data structure. This library supports the
conversions from previous three data source to the following list of data structures, and vice versa.
1 quoted from whatis.com. Technical details can be found at MSDN XLS
2 xlsx is used by MS-Excel 2007, more information can be found at MSDN XLSX
10 Chapter 4. Design
pyexcel Documentation, Release 0.6.0
The main operation on a cell involves cell access, formatting and cleansing. The main operation on a sheet involves
group access to a row or a column; data filtering; and data transformation. The main operation in a book is obtain
access to individual sheets.
For various reasons the data in one format needs to be transcoded into another. This library provides a transcoding
tunnel for data transcoding between supported file formats.
4.1. Introduction 11
pyexcel Documentation, Release 0.6.0
| Firefox | IE |
+---------+-----+
| 0.3 | 0.2 |
+---------+-----+
>>> a_dictionary_of_one_dimensional_arrays = {
... "Column 1": [1, 2, 3, 4],
... "Column 2": [5, 6, 7, 8],
... "Column 3": [9, 10, 11, 12],
... }
>>> p.get_sheet(adict=a_dictionary_of_one_dimensional_arrays)
pyexcel_sheet1:
+----------+----------+----------+
| Column 1 | Column 2 | Column 3 |
+----------+----------+----------+
| 1 | 5 | 9 |
+----------+----------+----------+
| 2 | 6 | 10 |
+----------+----------+----------+
| 3 | 7 | 11 |
+----------+----------+----------+
| 4 | 8 | 12 |
+----------+----------+----------+
>>> a_list_of_dictionaries = [
... {
... "Name": 'Adam',
... "Age": 28
... },
... {
... "Name": 'Beatrice',
... "Age": 29
... },
... {
... "Name": 'Ceri',
... "Age": 30
... },
... {
... "Name": 'Dean',
... "Age": 26
... }
... ]
>>> p.get_sheet(records=a_list_of_dictionaries)
pyexcel_sheet1:
+-----+----------+
| Age | Name |
+-----+----------+
| 28 | Adam |
+-----+----------+
| 29 | Beatrice |
+-----+----------+
| 30 | Ceri |
+-----+----------+
| 26 | Dean |
+-----+----------+
>>> a_dictionary_of_two_dimensional_arrays = {
... 'Sheet 1':
... [
... [1.0, 2.0, 3.0],
... [4.0, 5.0, 6.0],
12 Chapter 4. Design
pyexcel Documentation, Release 0.6.0
This library provides one application programming interface to read data from one of the following data sources:
• physical file
• memory file
• SQLAlchemy table
• Django Model
• Python data structures: dictionary, records and array
Python data can be handled well using lists, dictionaries and various mixture of both. This library provides four
module level functions to help you obtain excel data in these data structures. Please refer to “A list of module level
functions”, the first three functions operates on any one sheet from an excel book and the fourth one returns all data in
all sheets in an excel book.
See also:
• How to get an array from an excel sheet
• How to get a dictionary from an excel sheet
• How to obtain records from an excel sheet
• How to obtain a dictionary from a multiple sheet book
The following two variants of the data access function use generator and should work well with big data files
However, you will need to call free_resource() to make sure file handles are closed.
In cases where the excel data needs custom manipulations, a pyexcel user got a few choices: one is to use Sheet and
Book, the other is to look for more sophisticated ones:
• Pandas, for numerical analysis
14 Chapter 4. Design
pyexcel Documentation, Release 0.6.0
• Do-it-yourself
Functions Returns
get_sheet() Sheet
get_book() Book
For all six functions, you can pass on the same command parameters while the return value is what the function says.
This library provides one application programming interface to transform them into one of the data structures:
• two dimensional array
• a (ordered) dictionary of one dimensional arrays
• a list of dictionaries
• a dictionary of two dimensional arrays
• a Sheet
• a Book
and write to one of the following data sources:
• physical file
• memory file
• SQLAlchemy table
• Django Model
• Python data structures: dictionary, records and array
Here are the two functions:
Functions Description
save_as() Works well with single sheet file
isave_as() Works well with big data files
save_book_as()
Works with multiple sheet file and big data files
isave_book_as()
Works with multiple sheet file and big data files
If you would only use these two functions to do format transcoding, you may enjoy a speed boost using isave_as()
and isave_book_as(), because they use yield keyword and minimize memory footprint. However, you will need
to call free_resource() to make sure file handles are closed. And save_as() and save_book_as() reads
all data into memory and will make all rows the same width.
See also:
• How to save an python array as an excel file
• How to save a dictionary of two dimensional array as an excel file
• How to save an python array as a csv file with special delimiter
This library is capable of transporting your data between any of the following data sources:
• physical file
• memory file
• SQLAlchemy table
• Django Model
• Python data structures: dictionary, records and array
See also:
• How to an excel sheet to a database using SQLAlchemy
• How to open an xls file and save it as xlsx
• How to open an xls file and save it as csv
4.3 Architecture
pyexcel uses loosely couple plugins to fullfil the promise to access various file formats. lml is the plugin management
library that provide the specialized support for the loose coupling.
The components of pyexcel is designed as building blocks. For your project, you can cherry-pick the file format
support without affecting the core functionality of pyexcel. Each plugin will bring in additional dependences. For
example, if you choose pyexcel-xls, xlrd and xlwt will be brought in as 2nd level depndencies.
Looking at the following architectural diagram, pyexcel hosts plugin interfaces for data source, data renderer and
data parser. pyexel-pygal, pyexcel-matplotlib, and pyexce-handsontable extend pyexcel using data renderer interface.
pyexcel-io package takes away the responsibilities to interface with excel libraries, for example: xlrd, openpyxl, ezodf.
As in A list of file formats supported by external plugins, there are overlapping capabilities in reading and writing xlsx,
ods files. Because each third parties express different personalities although they may read and write data in the same
file format, you as the pyexcel is left to pick which suit your task best.
Dotted arrow means the package or module is loaded later.
16 Chapter 4. Design
CHAPTER 5
Tutorial
Warning: The pyexcel DOES NOT consider Fonts, Styles, Formulas and Charts at all. When you load a stylish
excel and update it, you definitely will lose all those styles.
17
pyexcel Documentation, Release 0.6.0
| 3 | 6 | 9 |
+---+---+---+
Note: a tab separated file can be read as csv: just specify tab as a delimiter parameter.
Suppose you want to update the last row of the example file as:
[‘N/A’, ‘N/A’, ‘N/A’]
Here is the sample code:
.. code-block:: python
18 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
+----------+----------+----------+
| 1 | 4 | 100 |
+----------+----------+----------+
| 2 | 5 | 200 |
+----------+----------+----------+
| 3 | 6 | 300 |
+----------+----------+----------+
How about the same alternative solution to previous row based example? Let’s use the following data:
And then you want to update “Row 3” with for example:
[100, 200, 300]
Excel files in memory can be manipulated directly without saving it to physical disk and vice versa. This is useful in
excel file handling at file upload or in excel file download. For example:
>>> import pyexcel
>>> content = "1,2,3\n3,4,5"
>>> sheet = pyexcel.get_sheet(file_type="csv", file_content=content)
20 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
>>> sheet.csv
'1,2,3\r\n3,4,5\r\n'
Since version 0.3.0, each supported file types became an attribute of the Sheet and Book class. What it means is that:
1. Read the content in memory
2. Set the content in memory
For example, after you have your Sheet and Book instance, you could access its content in a support file type by using
its dot notation. The code in previous section could be rewritten as:
>>> import pyexcel
>>> content = "1,2,3\n3,4,5"
>>> sheet = pyexcel.Sheet()
>>> sheet.csv = content
>>> sheet.array
[[1, 2, 3], [3, 4, 5]]
5.2.2 Read any supported excel and respond its content in json
You can find a real world example in examples/memoryfile/ directory: pyexcel_server.py. Here is the example snippet
1 def upload():
2 if request.method == 'POST' and 'excel' in request.files:
3 # handle file upload
4 filename = request.files['excel'].filename
5 extension = filename.split(".")[-1]
6 # Obtain the file extension and content
7 # pass a tuple instead of a file name
8 content = request.files['excel'].read()
9 if sys.version_info[0] > 2:
10 # in order to support python 3
11 # have to decode bytes to str
12 content = content.decode('utf-8')
13 sheet = pe.get_sheet(file_type=extension, file_content=content)
14 # then use it as usual
15 sheet.name_columns_by_row(0)
16 # respond with a json
17 return jsonify({"result": sheet.dict})
18 return render_template('upload.html')
request.files[‘excel’] in line 4 holds the file object. line 5 finds out the file extension. line 13 obtains a sheet instance.
line 15 uses the first row as data header. line 17 sends the json representation of the excel file back to client browser.
1 data = [
2 [...],
3 ...
4 ]
5
6 @app.route('/download')
7 def download():
8 sheet = pe.Sheet(data)
9 output = make_response(sheet.csv)
10 output.headers["Content-Disposition"] = "attachment; filename=export.csv"
11 output.headers["Content-type"] = "text/csv"
12 return output
Relevant packages
Readily made plugins have been made on top of this example. Here is a list of them:
framework plugin/middleware/extension
Flask Flask-Excel
Django django-excel
Pyramid pyramid-excel
22 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
>>> my_array
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> pyexcel.get_sheet(file_name="example.xls")
pyexcel_sheet1:
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+
5.3.4 How to save an python array as a csv file with special delimiter
>>> a_dictionary_of_two_dimensional_arrays = {
... 'Sheet 1':
... [
... [1.0, 2.0, 3.0],
... [4.0, 5.0, 6.0],
... [7.0, 8.0, 9.0]
... ],
... 'Sheet 2':
... [
... ['X', 'Y', 'Z'],
... [1.0, 2.0, 3.0],
... [4.0, 5.0, 6.0]
... ],
... 'Sheet 3':
... [
... ['O', 'P', 'Q'],
... [3.0, 2.0, 1.0],
... [4.0, 3.0, 2.0]
... ]
... }
24 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
>>> pyexcel.save_book_as(
... bookdict=a_dictionary_of_two_dimensional_arrays,
... dest_file_name="book.xls"
... )
If you want to preserve the order of sheets in your dictionary, you have to pass on an ordered dictionary to the function
itself. For example:
Please notice that “Sheet 2” is the first item in the book_dict, meaning the order of sheets are preserved.
Note: You can find the complete code of this example in examples folder on github
Before going ahead, let’s import the needed components and initialize sql engine and table base:
>>> Base.metadata.create_all(engine)
Done it. It is that simple. Let’s verify what has been imported to make sure.
Note: Please note that csv(comma separate value) file is pure text file. Formula, charts, images and formatting in xls
file will disappear no matter which transcoding tool you use. Hence, pyexcel is a quick alternative for this transcoding
job.
Warning: Formula, charts, images and formatting in xls file will disappear as pyexcel does not support Formula,
charts, images and formatting.
26 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
5.3.11 How to open a xls multiple sheet excel book and save it as csv
Well, you write similar codes as before but you will need to use save_book_as() function.
Since version 0.3.0, the data source becomes an attribute of the pyexcel native classes. All support data format is a dot
notation away.
Get content
What’s more, you could as well set value to an attribute, for example:
>>> import pyexcel
>>> content = "1,2,3\n3,4,5"
>>> sheet = pyexcel.Sheet()
>>> sheet.csv = content
>>> sheet.array
[[1, 2, 3], [3, 4, 5]]
You can get the direct access to underneath stream object. In some situation, it is desired.
The returned stream object has tsv formatted content for reading.
Set content
What you could further do is to set a memory stream of any supported file format to a sheet. For example:
>>> another_sheet = pyexcel.Sheet()
>>> another_sheet.xls = sheet.xls
>>> another_sheet.content
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 3 | 4 | 5 |
+---+---+---+
Yet, it is possible assign a absolute url to an online excel file to an instance of pyexcel.Sheet.
>>> another_sheet.url = "https://github.com/pyexcel/pyexcel/raw/master/examples/
˓→basics/multiple-sheets-example.xls"
>>> another_sheet.content
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+
Get content
>>> book_dict = {
... 'Sheet 2':
... [
... ['X', 'Y', 'Z'],
... [1.0, 2.0, 3.0],
... [4.0, 5.0, 6.0]
... ],
... 'Sheet 3':
... [
... ['O', 'P', 'Q'],
... [3.0, 2.0, 1.0],
... [4.0, 3.0, 2.0]
... ],
... 'Sheet 1':
... [
... [1.0, 2.0, 3.0],
... [4.0, 5.0, 6.0],
... [7.0, 8.0, 9.0]
28 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
... ]
... }
>>> book = pyexcel.get_book(bookdict=book_dict)
>>> book
Sheet 1:
+-----+-----+-----+
| 1.0 | 2.0 | 3.0 |
+-----+-----+-----+
| 4.0 | 5.0 | 6.0 |
+-----+-----+-----+
| 7.0 | 8.0 | 9.0 |
+-----+-----+-----+
Sheet 2:
+-----+-----+-----+
| X | Y | Z |
+-----+-----+-----+
| 1.0 | 2.0 | 3.0 |
+-----+-----+-----+
| 4.0 | 5.0 | 6.0 |
+-----+-----+-----+
Sheet 3:
+-----+-----+-----+
| O | P | Q |
+-----+-----+-----+
| 3.0 | 2.0 | 1.0 |
+-----+-----+-----+
| 4.0 | 3.0 | 2.0 |
+-----+-----+-----+
>>> print(book.rst)
Sheet 1:
= = =
1 2 3
4 5 6
7 8 9
= = =
Sheet 2:
=== === ===
X Y Z
1.0 2.0 3.0
4.0 5.0 6.0
=== === ===
Sheet 3:
=== === ===
O P Q
3.0 2.0 1.0
4.0 3.0 2.0
=== === ===
You can get the direct access to underneath stream object. In some situation, it is desired.
>>> stream = sheet.stream.plain
The returned stream object has the content formatted in plain format for further reading.
Set content
>>> another_book
Sheet 1:
30 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+
Sheet 2:
+---+---+---+
| X | Y | Z |
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
Sheet 3:
+---+---+---+
| O | P | Q |
+---+---+---+
| 3 | 2 | 1 |
+---+---+---+
| 4 | 3 | 2 |
+---+---+---+
You can pass on source specific parameters to getter and setter functions.
5.5.1 Pagination
When you are dealing with huge amount of data, e.g. 64GB, obviously you would not like to fill up your memory with
those data. Hence pagination feature is developed to read partial data into memory for processing. You can paginate
by row, by column and by both.
Let’s assume the following file is a huge csv file:
>>> pe.get_sheet(file_name="your_file.csv",
... start_row=2, row_limit=3,
... start_column=1, column_limit=2)
your_file.csv:
+----+----+
| 23 | 33 |
+----+----+
| 24 | 34 |
+----+----+
| 25 | 35 |
+----+----+
32 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
If you are transcoding a big data set, conventional formatting method would not help unless a on-demand free RAM
is available. However, there is a way to minimize the memory footprint of pyexcel while the formatting is performed.
Let’s continue from previous example. Suppose we want to transcode “your_file.csv” to “your_file.xls” but increase
each element by 1.
What we can do is to define a row renderer function as the following:
>>> def increment_by_one(row):
... for element in row:
... yield element + 1
Here is the way to read the csv file and iterate through each row:
>>> sheet = pyexcel.get_sheet(file_name='tutorial.csv')
>>> for row in sheet:
... print("%s: %s" % (row[0], row[1]))
Name: Age
Chu Chu: 10
Mo mo: 11
Often people wanted to use csv.Dict reader to read it because it has a header. Here is how you do it with pyexcel:
Line 2 remove the header from the actual content. The removed header can be used to access its columns using the
name itself, for example:
>>> sheet.column['Age']
[10, 11]
or:
sheet['A1']
The former syntax is handy when you know the row and column numbers. The latter syntax is introduced to help you
convert the excel column header such as “AX” to integer numbers.
Suppose you have the following data, you can get value 5 by reader[2, 2].
Here is the example code showing how you can randomly access a cell:
>>> sheet = pyexcel.get_sheet(file_name="example.xls")
>>> sheet.content
+---------+---+---+---+
| Example | X | Y | Z |
+---------+---+---+---+
| a | 1 | 2 | 3 |
+---------+---+---+---+
| b | 4 | 5 | 6 |
+---------+---+---+---+
| c | 7 | 8 | 9 |
+---------+---+---+---+
>>> print(sheet[2, 2])
5
>>> print(sheet["C3"])
5
>>> sheet[3, 3] = 10
>>> print(sheet[3, 3])
10
Note: In order to set a value to a cell, please use sheet[row_index, column_index] = new_value
Continue with previous excel file, you can access row and column separately:
34 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
>>> sheet.row[1]
['a', 1, 2, 3]
>>> sheet.column[2]
['Y', 2, 5, 8]
You have noticed the row index has been changed. It is because first row is taken as the column names, hence all rows
after the first row are shifted. Now accessing the columns are changed too:
>>> sheet.column['Y']
[2, 100, 8]
For the same reason, the row index has been reduced by 1. Since we have named columns and rows, it is possible to
access the same cell like this:
>>> print(sheet["b", "Y"])
100
>>> sheet["b", "Y"] = 200
>>> print(sheet["b", "Y"])
200
Note: When you have named your rows and columns, in order to set a value to a cell, please use sheet[row_name,
column_name] = new_value
For multiple sheet file, you can regard it as three dimensional array if you use Book. So, you access each cell via this
syntax:
book[sheet_index][row, column]
or:
book["sheet_name"][row, column]
Tip: With pyexcel, you can regard single sheet reader as an two dimensional array and multi-sheet excel book reader
as a ordered dictionary of two dimensional arrays.
>>> # "example.xls","example.xlsx","example.xlsm"
>>> sheet = pyexcel.get_sheet(file_name="example_series.xls", name_columns_by_row=0)
>>> sheet.to_dict()
OrderedDict([('Column 1', [1, 4, 7]), ('Column 2', [2, 5, 8]), ('Column 3', [3, 6,
˓→9])])
>>> # "example.csv","example.xlsx","example.xlsm"
>>> sheet = pyexcel.get_sheet(file_name="example.xls", name_columns_by_row=0)
>>> records = sheet.to_records()
>>> for record in records:
... keys = sorted(record.keys())
... print("{")
36 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
1 2 3
4 5 6
7 8 9
.. testcode::
>>> example_dict = {"Column 1": [1, 2, 3], "Column 2": [4, 5, 6], "Column 3": [7, 8,
˓→9]}
Suppose you have previous data as a dictionary and you want to save it as multiple sheet excel file:
>>> content = {
... 'Sheet 1':
... [
... [1.0, 2.0, 3.0],
... [4.0, 5.0, 6.0],
... [7.0, 8.0, 9.0]
... ],
... 'Sheet 2':
... [
... ['X', 'Y', 'Z'],
... [1.0, 2.0, 3.0],
... [4.0, 5.0, 6.0]
... ],
... 'Sheet 3':
... [
... ['O', 'P', 'Q'],
... [3.0, 2.0, 1.0],
... [4.0, 3.0, 2.0]
... ]
... }
>>> book = pyexcel.get_book(bookdict=content)
>>> book.save_as("output.xls")
Suppose you have the following data in any of the supported excel formats again:
>>> print(list(sheet.colnames))
['Column 1', 'Column 2', 'Column 3']
38 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
>>> sheet.to_dict()
OrderedDict([('Column 1', [1, 4, 7]), ('Column 2', [2, 5, 8]), ('Column 3', [3, 6,
˓→9])])
Maybe you want to get only the data without the column headers. You can call rows() instead:
>>> list(sheet.rows())
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
You can get data from the bottom to the top one by calling rrows() instead:
>>> list(sheet.rrows())
[[7, 8, 9], [4, 5, 6], [1, 2, 3]]
You might want the data arranged vertically. You can call columns() instead:
>>> list(sheet.columns())
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]
You can get columns in reverse sequence as well by calling rcolumns() instead:
>>> list(sheet.rcolumns())
[[3, 6, 9], [2, 5, 8], [1, 4, 7]]
Do you want to flatten the data? You can get the content in one dimensional array. If you are interested in playing with
one dimensional enumeration, you can check out these functions enumerate(), reverse(), vertical(), and
rvertical():
>>> list(sheet.enumerate())
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(sheet.reverse())
[9, 8, 7, 6, 5, 4, 3, 2, 1]
>>> list(sheet.vertical())
[1, 4, 7, 2, 5, 8, 3, 6, 9]
>>> list(sheet.rvertical())
[9, 6, 3, 8, 5, 2, 7, 4, 1]
The data in a sheet is represented by Sheet which maintains the data as a list of lists. You can regard Sheet as a
two dimensional array with additional iterators. Random access to individual column and row is exposed by Column
and Row
| 1 | 4 | 7 |
+----------+----------+----------+
| 2 | 5 | 8 |
+----------+----------+----------+
| 3 | 6 | 9 |
+----------+----------+----------+
And you want to update Column 2 with these data: [11, 12, 13]
>>> sheet
pyexcel sheet:
+----------+----------+
| Column 1 | Column 3 |
+==========+==========+
| 1 | 7 |
+----------+----------+
| 2 | 8 |
+----------+----------+
| 3 | 9 |
+----------+----------+
Continue from previous example. Suppose you want add two more columns to the data file
Column 4 Column 5
10 13
11 14
12 15
40 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
>>> extra_data = [
... ["Column 4", "Column 5"],
... [10, 13],
... [11, 14],
... [12, 15]
... ]
>>> sheet2 = pyexcel.Sheet(extra_data)
>>> sheet.column += sheet2
>>> sheet.column["Column 4"]
[10, 11, 12]
>>> sheet.column["Column 5"]
[13, 14, 15]
>>> sheet
pyexcel sheet:
+----------+----------+----------+----------+
| Column 1 | Column 3 | Column 4 | Column 5 |
+==========+==========+==========+==========+
| 1 | 7 | 10 | 13 |
+----------+----------+----------+----------+
| 2 | 8 | 11 | 14 |
+----------+----------+----------+----------+
| 3 | 9 | 12 | 15 |
+----------+----------+----------+----------+
>>> data = [
... ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
... [1,2,3,4,5,6,7,9],
... ]
>>> sheet = pyexcel.Sheet(data, name_columns_by_row=0)
>>> sheet
pyexcel sheet:
+---+---+---+---+---+---+---+---+
| a | b | c | d | e | f | g | h |
+===+===+===+===+===+===+===+===+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 |
+---+---+---+---+---+---+---+---+
And you want to remove columns named as: ‘a’, ‘c, ‘e’, ‘h’. This is how you do it:
>>> sheet
pyexcel sheet:
+----------+----------+----------+
| 1 | 2 | 3 |
+----------+----------+----------+
| Column 1 | Column 2 | Column 3 |
+----------+----------+----------+
| 4 | 5 | 6 |
+----------+----------+----------+
>>> sheet.name_columns_by_row(1)
>>> sheet
pyexcel sheet:
+----------+----------+----------+
| Column 1 | Column 2 | Column 3 |
+==========+==========+==========+
| 1 | 2 | 3 |
+----------+----------+----------+
| 4 | 5 | 6 |
+----------+----------+----------+
>>> sheet
pyexcel sheet:
+---+---+---+-------+
| a | b | c | Row 1 |
+---+---+---+-------+
| e | f | g | Row 2 |
+---+---+---+-------+
| 1 | 2 | 3 | Row 3 |
+---+---+---+-------+
>>> sheet.name_rows_by_column(3)
>>> sheet
pyexcel sheet:
+-------+---+---+---+
| Row 1 | a | b | c |
+-------+---+---+---+
| Row 2 | e | f | g |
+-------+---+---+---+
| Row 3 | 1 | 2 | 3 |
+-------+---+---+---+
42 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
You may want to filter odd rows and print them in an array of dictionaries:
>>> sheet.filter(column_indices=[1])
>>> sheet.content
+----------+----------+
| Column 1 | Column 3 |
+==========+==========+
| 4 | 6 |
+----------+----------+
>>> sheet.save_as("example_series_filter.xls")
Column 1 Column 3
2 8
Suppose you have the following data in a sheet and you want to remove those rows with blanks:
You can use pyexcel.filters.RowValueFilter, which examines each row, return True if the row should be
filtered out. So, let’s define a filter function:
Previous section has assumed the data is in the format that you want. In reality, you have to manipulate the data types
a bit to suit your needs. Hence, formatters comes into the scene. use format() to apply formatter immediately.
Note: int, float and datetime values are automatically detected in csv files since pyexcel version 0.2.2
44 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
... [10120,"Adam"],
... [10121,"Bella"],
... [10122,"Cedar"]
... ]
>>> sheet = pyexcel.Sheet(data)
>>> sheet.name_columns_by_row(0)
>>> sheet.column["userid"]
[10120, 10121, 10122]
As you can see, userid column is of int type. Next, let’s convert the column to string format:
Sometimes, the data in a spreadsheet may have unwanted strings in all or some cells. Let’s take an example. Suppose
we have a spread sheet that contains all strings but it as random spaces before and after the text values. Some field had
weird characters, such as “ ”:
>>> data = [
... [" Version", " Comments", " Author "],
... [" v0.0.1 ", " Release versions"," Eda"],
... [" v0.0.2 ", "Useful updates ", " Freud"]
... ]
>>> sheet = pyexcel.Sheet(data)
>>> sheet.content
+-----------------+------------------------------+----------------------+
| Version | Comments | Author |
+-----------------+------------------------------+----------------------+
| v0.0.1 | Release versions | Eda |
+-----------------+------------------------------+----------------------+
| v0.0.2 | Useful updates | Freud |
+-----------------+------------------------------+----------------------+
.. code-block:: python
.. code-block:: python
>>> sheet.map(cleanse_func)
>>> sheet.content
+---------+------------------+--------+
| Version | Comments | Author |
+---------+------------------+--------+
| v0.0.1 | Release versions | Eda |
+---------+------------------+--------+
| v0.0.2 | Useful updates | Freud |
+---------+------------------+--------+
Suppose you have two excel books and each had three sheets. You can merge them and get a new book:
You also can merge individual sheets:
46 Chapter 5. Tutorial
pyexcel Documentation, Release 0.6.0
Suppose you want to merge many csv files row by row into a new sheet.
import pyexcel
book = pyexcel.get_book(file_name="yourfile.xls")
for sheet in book:
# do you processing with sheet
# do filtering?
pass
book.save_as("output.xls")
5.10.5 What would happen if I save a multi sheet book into “csv” file
Well, you will get one csv file per each sheet. Suppose you have these code:
>>> content = {
... 'Sheet 1':
... [
... [1.0, 2.0, 3.0],
... [4.0, 5.0, 6.0],
... [7.0, 8.0, 9.0]
... ],
... 'Sheet 2':
... [
... ['X', 'Y', 'Z'],
... [1.0, 2.0, 3.0],
... [4.0, 5.0, 6.0]
... ],
... 'Sheet 3':
... [
... ['O', 'P', 'Q'],
... [3.0, 2.0, 1.0],
... [4.0, 3.0, 2.0]
... ]
... }
>>> book = pyexcel.Book(content)
>>> book.save_as("myfile.csv")
and their content is the value of the dictionary at the corresponding key
Alternatively, you could use save_book_as() function
5.10.6 After I have saved my multiple sheet book in csv format, how do I get them
back
First of all, you can read them back individual as csv file using meth:~pyexcel.get_sheet method. Secondly, the pyexcel
can do the magic to load all of them back into a book. You will just need to provide the common name before the
separator “__”:
48 Chapter 5. Tutorial
CHAPTER 6
Cook book
6.1 Recipes
Warning: The pyexcel DOES NOT consider Fonts, Styles and Charts at all. In the resulting excel files, fonts,
styles and charts will not be transferred.
These recipes give a one-stop utility functions for known use cases. Similar functionality can be achieved using other
application interfaces.
And you want to update Column 2 with these data: [11, 12, 13]
Here is the code:
49
pyexcel Documentation, Release 0.6.0
Row 1 1 2 3
Row 2 4 5 6
Row 3 7 8 9
And you want to update the second row with these data: [7, 4, 1]
Here is the code:
>>> from pyexcel.cookbook import update_rows
>>> custom_row = {"Row 1":[11, 12, 13]}
>>> update_rows("example.xls", custom_row, "output.xls")
example.xls
Column 4 Column 5
10 12
11 13
The following code will merge the tow into one file, say “output.xls”:
>>> from pyexcel.cookbook import merge_two_files
>>> merge_two_files("example.csv", "example.xls", "output.xls")
6.1.4 Select candidate columns of two files and form a new one
example.xls
>>> data = [
... ["Column 1", "Column 2", "Column 3", "Column 4", "Column 5"],
... [1, 4, 7, 10, 13],
... [2, 5, 8, 11, 14],
... [3, 6, 9, 12, 15]
... ]
>>> s = pyexcel.Sheet(data)
>>> s.save_as("example.csv")
>>> data = [
... ["Column 6", "Column 7", "Column 8", "Column 9", "Column 10"],
... [16, 17, 18, 19, 20]
... ]
>>> s = pyexcel.Sheet(data)
>>> s.save_as("example.xls")
And you want to filter out column 2 and 4 from example.ods, filter out column 6 and 7 and merge them:
6.1. Recipes 51
pyexcel Documentation, Release 0.6.0
6.1.5 Merge two files into a book where each file become a sheet
example.xls
Column 4 Column 5
10 12
11 13
>>> data = [
... ["Column 1", "Column 2", "Column 3"],
... [1, 2, 3],
... [4, 5, 6],
... [7, 8, 9]
... ]
>>> s = pyexcel.Sheet(data)
>>> s.save_as("example.csv")
>>> data = [
... ["Column 4", "Column 5"],
... [10, 12],
... [11, 13]
... ]
>>> s = pyexcel.Sheet(data)
>>> s.save_as("example.xls")
The following code will merge the tow into one file, say “output.xls”:
Column 4 Column 5
10 12
11 13
6.1.6 Merge all excel files in directory into a book where each file become a sheet
The following code will merge every excel files into one file, say “output.xls”:
merge_all_to_a_book(glob.glob("your_csv_directory\*.csv"), "output.xls")
You can mix and match with other excel formats: xls, xlsm and ods. For example, if you are sure you have only xls,
xlsm, xlsx, ods and csv files in your_excel_file_directory, you can do the following:
merge_all_to_a_book(glob.glob("your_excel_file_directory\*.*"), "output.xls")
Suppose you have many sheets in a work book and you would like to separate each into a single sheet excel file. You
can easily do this:
for the output file, you can specify any of the supported formats
Suppose you just want to extract one sheet from many sheets that exists in a work book and you would like to separate
it into a single sheet excel file. You can easily do this:
for the output file, you can specify any of the supported formats
6.1. Recipes 53
pyexcel Documentation, Release 0.6.0
Here is real case in the stack-overflow. Due to the author’s ignorance, the user would like to have the code in matlab
than Python. Hence, I am sharing my pyexcel solution here.
55
pyexcel Documentation, Release 0.6.0
If you could insert an id field to act as the primary key, it can be mapped using sqlalchemy’s ORM:
$ sqlite3 /tmp/stack2.db
sqlite> CREATE TABLE ALLPROTEINS (
...> ID INT,
...> Protein_ID CHAR(20),
...> PROTEIN_KEY INT,
...> VALUE_OF_KEY INT
...> );
Here is the short script to get data inserted into the database:
$ sqlite3 /tmp/stack2.db
sqlite> select * from allproteins
...> ;
|a001|123442|6
|a001|234335|0
|a001|234336|0
|a001|3549867|8
|b001|123442|4
|b001|234335|2
|b001|234336|0
|b001|234336|0
|c003|123442|0
|c003|234335|0
|c003|234336|0
|c003|3549867|5
API documentation
pyexcel.get_array
pyexcel.get_array(**keywords)
Obtain an array from an excel source
It accepts the same parameters as get_sheet() but return an array instead.
Not all parameters are needed. Here is a table
59
pyexcel Documentation, Release 0.6.0
source parameters
loading from file file_name, sheet_name, keywords
loading from string file_content, file_type, sheet_name, keywords
loading from stream file_stream, file_type, sheet_name, keywords
loading from sql session, table
loading from sql in django model
loading from query sets any query sets(sqlalchemy or django)
loading from dictionary adict, with_keys
loading from records records
loading from array array
loading from an url url
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
table : database table
model: a django model
adict: a dictionary of one dimensional arrays
url : a download http url for your excel file
with_keys : load with previous dictionary’s keys, default is True
records : a list of dictionaries that have the same keys
array : a two dimensional array, a list of lists
sheet_name : sheet name. if sheet_name is not given, the default sheet at index 0 is loaded
start_row [int] defaults to 0. It allows you to skip rows at the begginning
row_limit: int defaults to -1, meaning till the end of the whole sheet. It allows you to skip the tailing rows.
start_column [int] defaults to 0. It allows you to skip columns on your left hand side
column_limit: int defaults to -1, meaning till the end of the columns. It allows you to skip the tailing columns.
skip_row_func: It allows you to write your own row skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
skip_column_func: It allows you to write your own column skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
skip_empty_rows: bool Defaults to False. Toggle it to True if the rest of empty rows are useless, but it does
affect the number of rows.
row_renderer: You could choose to write a custom row renderer when the data is being read.
pyexcel.get_dict
pyexcel.get_dict(name_columns_by_row=0, **keywords)
Obtain a dictionary from an excel source
It accepts the same parameters as get_sheet() but return a dictionary instead.
Specifically: name_columns_by_row : specify a row to be a dictionary key. It is default to 0 or first row.
If you would use a column index 0 instead, you should do:
get_dict(name_columns_by_row=-1, name_rows_by_column=0)
source parameters
loading from file file_name, sheet_name, keywords
loading from string file_content, file_type, sheet_name, keywords
loading from stream file_stream, file_type, sheet_name, keywords
loading from sql session, table
loading from sql in django model
loading from query sets any query sets(sqlalchemy or django)
loading from dictionary adict, with_keys
loading from records records
loading from array array
loading from an url url
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
table : database table
model: a django model
adict: a dictionary of one dimensional arrays
url : a download http url for your excel file
with_keys : load with previous dictionary’s keys, default is True
records : a list of dictionaries that have the same keys
array : a two dimensional array, a list of lists
sheet_name : sheet name. if sheet_name is not given, the default sheet at index 0 is loaded
start_row [int] defaults to 0. It allows you to skip rows at the begginning
row_limit: int defaults to -1, meaning till the end of the whole sheet. It allows you to skip the tailing rows.
start_column [int] defaults to 0. It allows you to skip columns on your left hand side
column_limit: int defaults to -1, meaning till the end of the columns. It allows you to skip the tailing columns.
pyexcel.get_records
pyexcel.get_records(name_columns_by_row=0, **keywords)
Obtain a list of records from an excel source
It accepts the same parameters as get_sheet() but return a list of dictionary(records) instead.
Specifically: name_columns_by_row : specify a row to be a dictionary key. It is default to 0 or first row.
If you would use a column index 0 instead, you should do:
get_records(name_columns_by_row=-1, name_rows_by_column=0)
source parameters
loading from file file_name, sheet_name, keywords
loading from string file_content, file_type, sheet_name, keywords
loading from stream file_stream, file_type, sheet_name, keywords
loading from sql session, table
loading from sql in django model
loading from query sets any query sets(sqlalchemy or django)
loading from dictionary adict, with_keys
loading from records records
loading from array array
loading from an url url
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
table : database table
model: a django model
adict: a dictionary of one dimensional arrays
url : a download http url for your excel file
with_keys : load with previous dictionary’s keys, default is True
records : a list of dictionaries that have the same keys
Parameters related to xls file format: Please note the following parameters apply to pyexcel-xls. more details
can be found in xlrd.open_workbook()
logfile: An open file to which messages and diagnostics are written.
verbosity: Increases the volume of trace material written to the logfile.
use_mmap: Whether to use the mmap module is determined heuristically. Use this arg to override the result.
Current heuristic: mmap is used if it exists.
encoding_override: Used to overcome missing or bad codepage information in older-version files.
formatting_info: The default is False, which saves memory.
When True, formatting information will be read from the spreadsheet file. This provides all cells, including
empty and blank cells. Formatting information is available for each cell.
ragged_rows: The default of False means all rows are padded out with empty cells so that all rows have the
same size as found in ncols.
True means that there are no empty cells at the ends of rows. This can result in substantial memory savings
if rows are of widely varying sizes. See also the row_len() method.
pyexcel.get_book_dict
pyexcel.get_book_dict(**keywords)
Obtain a dictionary of two dimensional arrays
It accepts the same parameters as get_book() but return a dictionary instead.
Here is a table of parameters:
source parameters
loading from file file_name, keywords
loading from string file_content, file_type, keywords
loading from stream file_stream, file_type, keywords
loading from sql session, tables
loading from django models models
loading from dictionary bookdict
loading from an url url
Where the dictionary should have text as keys and two dimensional array as values.
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
tables : a list of database table
models : a list of django models
bookdict : a dictionary of two dimensional arrays
url : a download http url for your excel file
sheets: a list of mixed sheet names and sheet indices to be read. This is done to keep Pandas compactibility.
With this parameter, more than one sheet can be read and you have the control to read the sheets of your
interest instead of all available sheets.
auto_detect_float : defaults to True
auto_detect_int : defaults to True
auto_detect_datetime : defaults to True
ignore_infinity : defaults to True
library : choose a specific pyexcel-io plugin for reading
source_library : choose a specific data source plugin for reading
parser_library : choose a pyexcel parser plugin for reading
skip_hidden_sheets: default is True. Please toggle it to read hidden sheets
Parameters related to csv file format
for csv, fmtparams are accepted
delimiter : field separator
lineterminator : line terminator
encoding: csv specific. Specify the file encoding the csv file. For example: encoding=’latin1’. Especially,
encoding=’utf-8-sig’ would add utf 8 bom header if used in renderer, or would parse a csv with utf brom
header used in parser.
escapechar : A one-character string used by the writer to escape the delimiter if quoting is set to
QUOTE_NONE and the quotechar if doublequote is False.
quotechar : A one-character string used to quote fields containing special characters, such as the delimiter or
quotechar, or which contain new-line characters. It defaults to ‘”’
quoting : Controls when quotes should be generated by the writer and recognised by the reader. It can take on
any of the QUOTE_* constants (see section Module Contents) and defaults to QUOTE_MINIMAL.
skipinitialspace : When True, whitespace immediately following the delimiter is ignored. The default is False.
pyexcel.get_book
pyexcel.get_book(**keywords)
Get an instance of Book from an excel source
Here is a table of parameters:
source parameters
loading from file file_name, keywords
loading from string file_content, file_type, keywords
loading from stream file_stream, file_type, keywords
loading from sql session, tables
loading from django models models
loading from dictionary bookdict
loading from an url url
Where the dictionary should have text as keys and two dimensional array as values.
Parameters
pyexcel.get_sheet
pyexcel.get_sheet(**keywords)
Get an instance of Sheet from an excel source
source parameters
loading from file file_name, sheet_name, keywords
loading from string file_content, file_type, sheet_name, keywords
loading from stream file_stream, file_type, sheet_name, keywords
loading from sql session, table
loading from sql in django model
loading from query sets any query sets(sqlalchemy or django)
loading from dictionary adict, with_keys
loading from records records
loading from array array
loading from an url url
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
table : database table
model: a django model
adict: a dictionary of one dimensional arrays
url : a download http url for your excel file
with_keys : load with previous dictionary’s keys, default is True
records : a list of dictionaries that have the same keys
array : a two dimensional array, a list of lists
sheet_name : sheet name. if sheet_name is not given, the default sheet at index 0 is loaded
start_row [int] defaults to 0. It allows you to skip rows at the begginning
row_limit: int defaults to -1, meaning till the end of the whole sheet. It allows you to skip the tailing rows.
start_column [int] defaults to 0. It allows you to skip columns on your left hand side
column_limit: int defaults to -1, meaning till the end of the columns. It allows you to skip the tailing columns.
skip_row_func: It allows you to write your own row skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
skip_column_func: It allows you to write your own column skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
skip_empty_rows: bool Defaults to False. Toggle it to True if the rest of empty rows are useless, but it does
affect the number of rows.
row_renderer: You could choose to write a custom row renderer when the data is being read.
auto_detect_float : defaults to True
auto_detect_int : defaults to True
auto_detect_datetime : defaults to True
ignore_infinity : defaults to True
library : choose a specific pyexcel-io plugin for reading
source_library : choose a specific data source plugin for reading
parser_library : choose a pyexcel parser plugin for reading
skip_hidden_sheets: default is True. Please toggle it to read hidden sheets
Parameters related to csv file format
for csv, fmtparams are accepted
delimiter : field separator
lineterminator : line terminator
encoding: csv specific. Specify the file encoding the csv file. For example: encoding=’latin1’. Especially,
encoding=’utf-8-sig’ would add utf 8 bom header if used in renderer, or would parse a csv with utf brom
header used in parser.
escapechar : A one-character string used by the writer to escape the delimiter if quoting is set to
QUOTE_NONE and the quotechar if doublequote is False.
quotechar : A one-character string used to quote fields containing special characters, such as the delimiter or
quotechar, or which contain new-line characters. It defaults to ‘”’
quoting : Controls when quotes should be generated by the writer and recognised by the reader. It can take on
any of the QUOTE_* constants (see section Module Contents) and defaults to QUOTE_MINIMAL.
skipinitialspace : When True, whitespace immediately following the delimiter is ignored. The default is False.
Parameters related to xls file format: Please note the following parameters apply to pyexcel-xls. more details
can be found in xlrd.open_workbook()
logfile: An open file to which messages and diagnostics are written.
verbosity: Increases the volume of trace material written to the logfile.
use_mmap: Whether to use the mmap module is determined heuristically. Use this arg to override the result.
Current heuristic: mmap is used if it exists.
encoding_override: Used to overcome missing or bad codepage information in older-version files.
formatting_info: The default is False, which saves memory.
When True, formatting information will be read from the spreadsheet file. This provides all cells, including
empty and blank cells. Formatting information is available for each cell.
ragged_rows: The default of False means all rows are padded out with empty cells so that all rows have the
same size as found in ncols.
True means that there are no empty cells at the ends of rows. This can result in substantial memory savings
if rows are of widely varying sizes. See also the row_len() method.
pyexcel.iget_array
pyexcel.iget_array(**keywords)
Obtain a generator of an two dimensional array from an excel source
It is similiar to pyexcel.get_array() but it has less memory footprint.
Not all parameters are needed. Here is a table
source parameters
loading from file file_name, sheet_name, keywords
loading from string file_content, file_type, sheet_name, keywords
loading from stream file_stream, file_type, sheet_name, keywords
loading from sql session, table
loading from sql in django model
loading from query sets any query sets(sqlalchemy or django)
loading from dictionary adict, with_keys
loading from records records
loading from array array
loading from an url url
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
table : database table
model: a django model
adict: a dictionary of one dimensional arrays
url : a download http url for your excel file
with_keys : load with previous dictionary’s keys, default is True
records : a list of dictionaries that have the same keys
array : a two dimensional array, a list of lists
sheet_name : sheet name. if sheet_name is not given, the default sheet at index 0 is loaded
start_row [int] defaults to 0. It allows you to skip rows at the begginning
row_limit: int defaults to -1, meaning till the end of the whole sheet. It allows you to skip the tailing rows.
start_column [int] defaults to 0. It allows you to skip columns on your left hand side
column_limit: int defaults to -1, meaning till the end of the columns. It allows you to skip the tailing columns.
skip_row_func: It allows you to write your own row skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
ragged_rows: The default of False means all rows are padded out with empty cells so that all rows have the
same size as found in ncols.
True means that there are no empty cells at the ends of rows. This can result in substantial memory savings
if rows are of widely varying sizes. See also the row_len() method.
When you use this function to work on physical files, this function will leave its file handle open. When you
finish the operation on its data, you need to call pyexcel.free_resources() to close file hande(s).
for csv, csvz file formats, file handles will be left open. for xls, ods file formats, the file is read all into memory
and is close afterwards. for xlsx, file handles will be left open in python 2.7 - 3.5 by pyexcel-xlsx(openpyxl). In
other words, pyexcel-xls, pyexcel-ods, pyexcel-ods3 won’t leak file handles.
pyexcel.iget_records
pyexcel.iget_records(custom_headers=None, **keywords)
Obtain a generator of a list of records from an excel source
It is similiar to pyexcel.get_records() but it has less memory footprint but requires the headers to be in
the first row. And the data matrix should be of equal length. It should consume less memory and should work
well with large files.
Not all parameters are needed. Here is a table
source parameters
loading from file file_name, sheet_name, keywords
loading from string file_content, file_type, sheet_name, keywords
loading from stream file_stream, file_type, sheet_name, keywords
loading from sql session, table
loading from sql in django model
loading from query sets any query sets(sqlalchemy or django)
loading from dictionary adict, with_keys
loading from records records
loading from array array
loading from an url url
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
table : database table
model: a django model
adict: a dictionary of one dimensional arrays
url : a download http url for your excel file
with_keys : load with previous dictionary’s keys, default is True
records : a list of dictionaries that have the same keys
array : a two dimensional array, a list of lists
sheet_name : sheet name. if sheet_name is not given, the default sheet at index 0 is loaded
start_row [int] defaults to 0. It allows you to skip rows at the begginning
row_limit: int defaults to -1, meaning till the end of the whole sheet. It allows you to skip the tailing rows.
start_column [int] defaults to 0. It allows you to skip columns on your left hand side
column_limit: int defaults to -1, meaning till the end of the columns. It allows you to skip the tailing columns.
skip_row_func: It allows you to write your own row skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
skip_column_func: It allows you to write your own column skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
skip_empty_rows: bool Defaults to False. Toggle it to True if the rest of empty rows are useless, but it does
affect the number of rows.
row_renderer: You could choose to write a custom row renderer when the data is being read.
auto_detect_float : defaults to True
auto_detect_int : defaults to True
auto_detect_datetime : defaults to True
ignore_infinity : defaults to True
library : choose a specific pyexcel-io plugin for reading
source_library : choose a specific data source plugin for reading
parser_library : choose a pyexcel parser plugin for reading
skip_hidden_sheets: default is True. Please toggle it to read hidden sheets
Parameters related to csv file format
for csv, fmtparams are accepted
delimiter : field separator
lineterminator : line terminator
encoding: csv specific. Specify the file encoding the csv file. For example: encoding=’latin1’. Especially,
encoding=’utf-8-sig’ would add utf 8 bom header if used in renderer, or would parse a csv with utf brom
header used in parser.
escapechar : A one-character string used by the writer to escape the delimiter if quoting is set to
QUOTE_NONE and the quotechar if doublequote is False.
quotechar : A one-character string used to quote fields containing special characters, such as the delimiter or
quotechar, or which contain new-line characters. It defaults to ‘”’
quoting : Controls when quotes should be generated by the writer and recognised by the reader. It can take on
any of the QUOTE_* constants (see section Module Contents) and defaults to QUOTE_MINIMAL.
skipinitialspace : When True, whitespace immediately following the delimiter is ignored. The default is False.
Parameters related to xls file format: Please note the following parameters apply to pyexcel-xls. more details
can be found in xlrd.open_workbook()
pyexcel.free_resources
pyexcel.free_resources()
Close file handles opened by signature functions that starts with ‘i’
for csv, csvz file formats, file handles will be left open. for xls, ods file formats, the file is read all into memory
and is close afterwards. for xlsx, file handles will be left open in python 2.7 - 3.5 by pyexcel-xlsx(openpyxl). In
other words, pyexcel-xls, pyexcel-ods, pyexcel-ods3 won’t leak file handles.
pyexcel.save_as
pyexcel.save_as(**keywords)
Save a sheet from a data source to another one
It accepts two sets of keywords. Why two sets? one set is source, the other set is destination. In order to distin-
guish the two sets, source set will be exactly the same as the ones for pyexcel.get_sheet(); destination
set are exactly the same as the ones for pyexcel.Sheet.save_as but require a ‘dest’ prefix.
source parameters
loading from file file_name, sheet_name, keywords
loading from string file_content, file_type, sheet_name, keywords
loading from stream file_stream, file_type, sheet_name, keywords
loading from sql session, table
loading from sql in django model
loading from query sets any query sets(sqlalchemy or django)
loading from dictionary adict, with_keys
loading from records records
loading from array array
loading from an url url
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
table : database table
model: a django model
adict: a dictionary of one dimensional arrays
url : a download http url for your excel file
with_keys : load with previous dictionary’s keys, default is True
records : a list of dictionaries that have the same keys
array : a two dimensional array, a list of lists
sheet_name : sheet name. if sheet_name is not given, the default sheet at index 0 is loaded
start_row [int] defaults to 0. It allows you to skip rows at the begginning
row_limit: int defaults to -1, meaning till the end of the whole sheet. It allows you to skip the tailing rows.
start_column [int] defaults to 0. It allows you to skip columns on your left hand side
column_limit: int defaults to -1, meaning till the end of the columns. It allows you to skip the tailing columns.
skip_row_func: It allows you to write your own row skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
ragged_rows: The default of False means all rows are padded out with empty cells so that all rows have the
same size as found in ncols.
True means that there are no empty cells at the ends of rows. This can result in substantial memory savings
if rows are of widely varying sizes. See also the row_len() method.
dest_file_name: another file name.
dest_file_type: this is needed if you want to save to memory
dest_session: the target database session
dest_table: the target destination table
dest_model: the target django model
dest_mapdict: a mapping dictionary see pyexcel.Sheet.save_to_memory()
dest_initializer: a custom initializer function for table or model
dest_mapdict: nominate headers
dest_batch_size: object creation batch size. it is Django specific
dest_library: choose a specific pyexcel-io plugin for writing
dest_source_library: choose a specific data source plugin for writing
dest_renderer_library: choose a pyexcel parser plugin for writing
if csv file is destination format, python csv fmtparams are accepted
for example: dest_lineterminator will replace default ‘ ‘ to the one you specified
In addition, this function use pyexcel.Sheet to render the data which could have performance penalty. In
exchange, parameters for pyexcel.Sheet can be passed on, e.g. name_columns_by_row.
pyexcel.isave_as
pyexcel.isave_as(**keywords)
Save a sheet from a data source to another one with less memory
It is simliar to pyexcel.save_as() except that it does not accept parameters for pyexcel.Sheet. And
it read when it writes.
It accepts two sets of keywords. Why two sets? one set is source, the other set is destination. In order to distin-
guish the two sets, source set will be exactly the same as the ones for pyexcel.get_sheet(); destination
set are exactly the same as the ones for pyexcel.Sheet.save_as but require a ‘dest’ prefix.
source parameters
loading from file file_name, sheet_name, keywords
loading from string file_content, file_type, sheet_name, keywords
loading from stream file_stream, file_type, sheet_name, keywords
loading from sql session, table
loading from sql in django model
loading from query sets any query sets(sqlalchemy or django)
loading from dictionary adict, with_keys
loading from records records
loading from array array
loading from an url url
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
table : database table
model: a django model
adict: a dictionary of one dimensional arrays
url : a download http url for your excel file
with_keys : load with previous dictionary’s keys, default is True
records : a list of dictionaries that have the same keys
array : a two dimensional array, a list of lists
sheet_name : sheet name. if sheet_name is not given, the default sheet at index 0 is loaded
start_row [int] defaults to 0. It allows you to skip rows at the begginning
row_limit: int defaults to -1, meaning till the end of the whole sheet. It allows you to skip the tailing rows.
start_column [int] defaults to 0. It allows you to skip columns on your left hand side
column_limit: int defaults to -1, meaning till the end of the columns. It allows you to skip the tailing columns.
skip_row_func: It allows you to write your own row skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
skip_column_func: It allows you to write your own column skipping functions.
The protocol is to return pyexcel_io.constants.SKIP_DATA if skipping data, pyex-
cel_io.constants.TAKE_DATA to read data, pyexcel_io.constants.STOP_ITERATION to exit the
reading procedure
skip_empty_rows: bool Defaults to False. Toggle it to True if the rest of empty rows are useless, but it does
affect the number of rows.
row_renderer: You could choose to write a custom row renderer when the data is being read.
pyexcel.save_book_as
pyexcel.save_book_as(**keywords)
Save a book from a data source to another one
Here is a table of parameters:
source parameters
loading from file file_name, keywords
loading from string file_content, file_type, keywords
loading from stream file_stream, file_type, keywords
loading from sql session, tables
loading from django models models
loading from dictionary bookdict
loading from an url url
Where the dictionary should have text as keys and two dimensional array as values.
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
tables : a list of database table
Where the dictionary should have text as keys and two dimensional array as values.
pyexcel.isave_book_as
pyexcel.isave_book_as(**keywords)
Save a book from a data source to another one
It is simliar to pyexcel.save_book_as() but it read when it writes. This function provide some speedup
but the output data is not made uniform.
Here is a table of parameters:
source parameters
loading from file file_name, keywords
loading from string file_content, file_type, keywords
loading from stream file_stream, file_type, keywords
loading from sql session, tables
loading from django models models
loading from dictionary bookdict
loading from an url url
Where the dictionary should have text as keys and two dimensional array as values.
Parameters
file_name : a file with supported file extension
file_content : the file content
file_stream : the file stream
file_type : the file type in file_content or file_stream
session : database session
tables : a list of database table
models : a list of django models
bookdict : a dictionary of two dimensional arrays
url : a download http url for your excel file
sheets: a list of mixed sheet names and sheet indices to be read. This is done to keep Pandas compactibility.
With this parameter, more than one sheet can be read and you have the control to read the sheets of your
interest instead of all available sheets.
auto_detect_float : defaults to True
auto_detect_int : defaults to True
auto_detect_datetime : defaults to True
ignore_infinity : defaults to True
When you use this function to work on physical files, this function will leave its file handle open. When you
finish the operation on its data, you need to call pyexcel.free_resources() to close file hande(s).
for csv, csvz file formats, file handles will be left open. for xls, ods file formats, the file is read all into memory
and is close afterwards. for xlsx, file handles will be left open in python 2.7 - 3.5 by pyexcel-xlsx(openpyxl). In
other words, pyexcel-xls, pyexcel-ods, pyexcel-ods3 won’t leak file handles.
These flags can be passed on all signature functions:
auto_detect_int
Automatically convert float values to integers if the float number has no decimal values(e.g. 1.00). By default, it does
the detection. Setting it to False will turn on this behavior
It has no effect on pyexcel-xlsx because it does that by default.
auto_detect_float
Automatically convert text to float values if possible. This applies only pyexcel-io where csv, tsv, csvz and tsvz formats
are supported. By default, it does the detection. Setting it to False will turn on this behavior
auto_detect_datetime
Automatically convert text to python datetime if possible. This applies only pyexcel-io where csv, tsv, csvz and tsvz
formats are supported. By default, it does the detection. Setting it to False will turn on this behavior
library
Name a pyexcel plugin to handle a file format. In the situation where multiple plugins were pip installed, it is confusing
for pyexcel on which plugin to handle the file format. For example, both pyexcel-xlsx and pyexcel-xls reads xlsx
format. Now since version 0.2.2, you can pass on library=”pyexcel-xls” to handle xlsx in a specific function call.
It is better to uninstall the unwanted pyexcel plugin using pip if two plugins for the same file type are not absolutely
necessary.
8.1.2 Cookbook
pyexcel.merge_csv_to_a_book
pyexcel.merge_csv_to_a_book(filelist, outfilename=’merged.xls’)
merge a list of csv files into a excel book
Parameters
• filelist (list) – a list of accessible file path
• outfilename (str) – save the sheet as
pyexcel.merge_all_to_a_book
pyexcel.merge_all_to_a_book(filelist, outfilename=’merged.xls’)
merge a list of excel files into a excel book
Parameters
pyexcel.split_a_book
pyexcel.split_a_book(file_name, outfilename=None)
Split a file into separate sheets
Parameters
• file_name (str) – an accessible file name
• outfilename (str) – save the sheets with file suffix
pyexcel.extract_a_sheet_from_a_book
8.1.3 Book
Here’s the entity relationship between Book, Sheet, Row and Column
Constructor
Book([sheets, filename, path]) Read an excel book that has one or more sheets
pyexcel.Book
Methods
Attributes
Attribute
pyexcel.Book.number_of_sheets
Book.number_of_sheets()
Return the number of sheets
pyexcel.Book.sheet_names
Book.sheet_names()
Return all sheet names
Conversions
pyexcel.Book.bookdict
Book.bookdict
Get/Set data in/from bookdict format
You could obtain content in bookdict format by dot notation:
Book.bookdict
Book.bookdict = the_io_stream_in_bookdict_format
Book.get_bookdict(**keywords)
Book.set_bookdict(the_io_stream_in_bookdict_format, **keywords)
pyexcel.Book.url
Book.url
Set data in url format
You could set content in url format by dot notation:
Book.url
Book.set_url(the_io_stream_in_url_format, **keywords)
pyexcel.Book.csv
Book.csv
Get/Set data in/from csv format
You could obtain content in csv format by dot notation:
Book.csv
Book.csv = the_io_stream_in_csv_format
Book.get_csv(**keywords)
Book.set_csv(the_io_stream_in_csv_format, **keywords)
pyexcel.Book.tsv
Book.tsv
Get/Set data in/from tsv format
You could obtain content in tsv format by dot notation:
Book.tsv
Book.tsv = the_io_stream_in_tsv_format
Book.get_tsv(**keywords)
Book.set_tsv(the_io_stream_in_tsv_format, **keywords)
pyexcel.Book.csvz
Book.csvz
Get/Set data in/from csvz format
You could obtain content in csvz format by dot notation:
Book.csvz
Book.csvz = the_io_stream_in_csvz_format
Book.get_csvz(**keywords)
Book.set_csvz(the_io_stream_in_csvz_format, **keywords)
pyexcel.Book.tsvz
Book.tsvz
Get/Set data in/from tsvz format
You could obtain content in tsvz format by dot notation:
Book.tsvz
Book.tsvz = the_io_stream_in_tsvz_format
Book.get_tsvz(**keywords)
Book.set_tsvz(the_io_stream_in_tsvz_format, **keywords)
pyexcel.Book.xls
Book.xls
Get/Set data in/from xls format
You could obtain content in xls format by dot notation:
Book.xls
Book.xls = the_io_stream_in_xls_format
Book.get_xls(**keywords)
Book.set_xls(the_io_stream_in_xls_format, **keywords)
pyexcel.Book.xlsm
Book.xlsm
Get/Set data in/from xlsm format
You could obtain content in xlsm format by dot notation:
Book.xlsm
Book.xlsm = the_io_stream_in_xlsm_format
Book.get_xlsm(**keywords)
Book.set_xlsm(the_io_stream_in_xlsm_format, **keywords)
pyexcel.Book.xlsx
Book.xlsx
Get/Set data in/from xlsx format
You could obtain content in xlsx format by dot notation:
Book.xlsx
Book.xlsx = the_io_stream_in_xlsx_format
Book.get_xlsx(**keywords)
Book.set_xlsx(the_io_stream_in_xlsx_format, **keywords)
pyexcel.Book.ods
Book.ods
Get/Set data in/from ods format
You could obtain content in ods format by dot notation:
Book.ods
Book.ods = the_io_stream_in_ods_format
Book.get_ods(**keywords)
Book.set_ods(the_io_stream_in_ods_format, **keywords)
pyexcel.Book.stream
Book.stream
Return a stream in which the content is properly encoded
Example:
Where b.stream.xls.getvalue() is equivalent to b.xls. In some situation b.stream.xls is prefered than b.xls.
Sheet examples:
Where s.stream.xls.getvalue() is equivalent to s.xls. In some situation s.stream.xls is prefered than s.xls.
It is similar to save_to_memory().
Save changes
pyexcel.Book.save_as
Book.save_as(filename, **keywords)
Save the content to a new file
Keywords may vary depending on your file type, because the associated file type employs different library.
PARAMETERS
filename: a file path
library: choose a specific pyexcel-io plugin for writing
renderer_library: choose a pyexcel parser plugin for writing
Parameters related to csv file format
for csv, fmtparams are accepted
delimiter : field separator
lineterminator : line terminator
encoding: csv specific. Specify the file encoding the csv file. For example: encoding=’latin1’. Especially,
encoding=’utf-8-sig’ would add utf 8 bom header if used in renderer, or would parse a csv with utf brom
header used in parser.
escapechar : A one-character string used by the writer to escape the delimiter if quoting is set to
QUOTE_NONE and the quotechar if doublequote is False.
quotechar : A one-character string used to quote fields containing special characters, such as the delimiter or
quotechar, or which contain new-line characters. It defaults to ‘”’
quoting : Controls when quotes should be generated by the writer and recognised by the reader. It can take on
any of the QUOTE_* constants (see section Module Contents) and defaults to QUOTE_MINIMAL.
skipinitialspace : When True, whitespace immediately following the delimiter is ignored. The default is False.
pyexcel.Book.save_to_memory
pyexcel.Book.save_to_database
pyexcel.Book.save_to_django_models
8.1.4 Sheet
Constructor
Sheet([sheet, name, name_columns_by_row, . . . ]) Two dimensional data container for filtering, formatting
and iteration
pyexcel.Sheet
In order to prepare two dimensional data for your computation, formatting functions help convert array cells
to required types. Formatting can be applied not only to the whole sheet but also to selected rows or columns.
Custom conversion function can be passed to these formatting functions. For example, to remove extra spaces
surrounding the content of a cell, a custom function is required.
Filtering functions are used to reduce the information contained in the array.
Variables
• name – sheet name. use to change sheet name
• row – access data row by row
• column – access data column by column
Example:
Methods
Attributes
Attributes
pyexcel.Sheet.content
Sheet.content
Plain representation without headers
pyexcel.Sheet.number_of_rows
Sheet.number_of_rows()
The number of rows
pyexcel.Sheet.number_of_columns
Sheet.number_of_columns()
The number of columns
pyexcel.Sheet.row_range
Sheet.row_range()
Utility function to get row range
pyexcel.Sheet.column_range
Sheet.column_range()
Utility function to get column range
Iteration
pyexcel.Sheet.rows
Sheet.rows()
Returns a top to bottom row iterator
example:
import pyexcel as pe
data = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
m = pe.internal.sheets.Matrix(data)
print(pe.utils.to_array(m.rows()))
output:
pyexcel.Sheet.rrows
Sheet.rrows()
Returns a bottom to top row iterator
import pyexcel as pe
data = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
m = pe.internal.sheets.Matrix(data)
print(pe.utils.to_array(m.rrows()))
pyexcel.Sheet.columns
Sheet.columns()
Returns a left to right column iterator
import pyexcel as pe
data = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
m = pe.internal.sheets.Matrix(data)
print(list(m.columns()))
pyexcel.Sheet.rcolumns
Sheet.rcolumns()
Returns a right to left column iterator
example:
import pyexcel as pe
data = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
m = pe.internal.sheets.Matrix(data)
print(pe.utils.to_array(m.rcolumns()))
output:
pyexcel.Sheet.enumerate
Sheet.enumerate()
Iterate cell by cell from top to bottom and from left to right
pyexcel.Sheet.reverse
Sheet.reverse()
Opposite to enumerate
each cell one by one from bottom row to top row and from right to left example:
pyexcel.Sheet.vertical
Sheet.vertical()
Default iterator to go through each cell one by one from leftmost column to rightmost row and from top to
bottom example:
import pyexcel as pe
data = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
m = pe.internal.sheets.Matrix(data)
print(list(m.vertical()))
output:
pyexcel.Sheet.rvertical
Sheet.rvertical()
Default iterator to go through each cell one by one from rightmost column to leftmost row and from bottom to
top example:
import pyexcel as pe
data = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
m = pe.internal.sheets.Matrix(data)
print(pe.utils.to_array(m.rvertical())
output:
Cell access
pyexcel.Sheet.cell_value
pyexcel.Sheet.__getitem__
Sheet.__getitem__(aset)
Row access
pyexcel.Sheet.row_at
Sheet.row_at(index)
Gets the data at the specified row
pyexcel.Sheet.set_row_at
Sheet.set_row_at(row_index, data_array)
Update a row data range
pyexcel.Sheet.delete_rows
Sheet.delete_rows(row_indices)
Delete one or more rows
Parameters row_indices (list) – a list of row indices
pyexcel.Sheet.extend_rows
Sheet.extend_rows(rows)
Take ordereddict to extend named rows
Parameters rows (ordereddist/list) – a list of rows.
Column access
pyexcel.Sheet.column_at
Sheet.column_at(index)
Gets the data at the specified column
pyexcel.Sheet.set_column_at
+--> column_index = 2
|
A B C
1 3 N <- starting = 1
2 4 N
This function will not set element outside the current table range
Parameters
• column_index (int) – which column to be modified
• data_array (list) – one dimensional array
pyexcel.Sheet.delete_columns
Sheet.delete_columns(column_indices)
Delete one or more columns
Parameters column_indices (list) – a list of column indices
pyexcel.Sheet.extend_columns
Sheet.extend_columns(columns)
Take ordereddict to extend named columns
Parameters columns (ordereddist/list) – a list of columns
Data series
pyexcel.Sheet.name_columns_by_row
Sheet.name_columns_by_row(row_index)
Use the elements of a specified row to represent individual columns
The specified row will be deleted from the data :param row_index: the index of the row that has the column
names
pyexcel.Sheet.rownames
Sheet.rownames
Return row names if any
pyexcel.Sheet.named_column_at
Sheet.named_column_at(name)
Get a column by its name
pyexcel.Sheet.set_named_column_at
Sheet.set_named_column_at(name, column_array)
Take the first row as column names
Given name to identify the column index, set the column to the given array except the column name.
pyexcel.Sheet.delete_named_column_at
Sheet.delete_named_column_at(name)
Works only after you named columns by a row
Given name to identify the column index, set the column to the given array except the column name. :param str
name: a column name
pyexcel.Sheet.name_rows_by_column
Sheet.name_rows_by_column(column_index)
Use the elements of a specified column to represent individual rows
The specified column will be deleted from the data :param column_index: the index of the column that has the
row names
pyexcel.Sheet.colnames
Sheet.colnames
Return column names if any
pyexcel.Sheet.named_row_at
Sheet.named_row_at(name)
Get a row by its name
pyexcel.Sheet.set_named_row_at
Sheet.set_named_row_at(name, row_array)
Take the first column as row names
Given name to identify the row index, set the row to the given array except the row name.
pyexcel.Sheet.delete_named_row_at
Sheet.delete_named_row_at(name)
Take the first column as row names
Given name to identify the row index, set the row to the given array except the row name.
Conversion
pyexcel.Sheet.array
Sheet.array
Get/Set data in/from array format
You could obtain content in array format by dot notation:
Sheet.array
Sheet.array = the_io_stream_in_array_format
Sheet.get_array(**keywords)
Sheet.set_array(the_io_stream_in_array_format, **keywords)
pyexcel.Sheet.records
Sheet.records
Get/Set data in/from records format
You could obtain content in records format by dot notation:
Sheet.records
Sheet.records = the_io_stream_in_records_format
Sheet.get_records(**keywords)
Sheet.set_records(the_io_stream_in_records_format, **keywords)
pyexcel.Sheet.dict
Sheet.dict
Get/Set data in/from dict format
You could obtain content in dict format by dot notation:
Sheet.dict
Sheet.dict = the_io_stream_in_dict_format
Sheet.get_dict(**keywords)
Sheet.set_dict(the_io_stream_in_dict_format, **keywords)
pyexcel.Sheet.url
Sheet.url
Set data in url format
You could set content in url format by dot notation:
Sheet.url
Sheet.set_url(the_io_stream_in_url_format, **keywords)
pyexcel.Sheet.csv
Sheet.csv
Get/Set data in/from csv format
You could obtain content in csv format by dot notation:
Sheet.csv
Sheet.csv = the_io_stream_in_csv_format
Sheet.get_csv(**keywords)
Sheet.set_csv(the_io_stream_in_csv_format, **keywords)
pyexcel.Sheet.tsv
Sheet.tsv
Get/Set data in/from tsv format
You could obtain content in tsv format by dot notation:
Sheet.tsv
pyexcel.Sheet.csvz
Sheet.csvz
Get/Set data in/from csvz format
You could obtain content in csvz format by dot notation:
Sheet.csvz
pyexcel.Sheet.tsvz
Sheet.tsvz
Get/Set data in/from tsvz format
You could obtain content in tsvz format by dot notation:
Sheet.tsvz
Sheet.get_tsvz(**keywords)
Sheet.set_tsvz(the_io_stream_in_tsvz_format, **keywords)
pyexcel.Sheet.xls
Sheet.xls
Get/Set data in/from xls format
You could obtain content in xls format by dot notation:
Sheet.xls
pyexcel.Sheet.xlsm
Sheet.xlsm
Get/Set data in/from xlsm format
You could obtain content in xlsm format by dot notation:
Sheet.xlsm
pyexcel.Sheet.xlsx
Sheet.xlsx
Get/Set data in/from xlsx format
You could obtain content in xlsx format by dot notation:
Sheet.xlsx
Sheet.get_xlsx(**keywords)
Sheet.set_xlsx(the_io_stream_in_xlsx_format, **keywords)
pyexcel.Sheet.ods
Sheet.ods
Get/Set data in/from ods format
You could obtain content in ods format by dot notation:
Sheet.ods
Sheet.ods = the_io_stream_in_ods_format
Sheet.get_ods(**keywords)
Sheet.set_ods(the_io_stream_in_ods_format, **keywords)
pyexcel.Sheet.stream
Sheet.stream
Return a stream in which the content is properly encoded
Example:
Where b.stream.xls.getvalue() is equivalent to b.xls. In some situation b.stream.xls is prefered than b.xls.
Sheet examples:
Where s.stream.xls.getvalue() is equivalent to s.xls. In some situation s.stream.xls is prefered than s.xls.
It is similar to save_to_memory().
Formatting
pyexcel.Sheet.format
Sheet.format(formatter)
Apply a formatting action for the whole sheet
Example:
Filtering
pyexcel.Sheet.filter
Sheet.filter(column_indices=None, row_indices=None)
Apply the filter with immediate effect
Transformation
Sheet.transpose()
Sheet.map(custom_function) Execute a function across all cells of the sheet
Sheet.region(topleft_corner, bottomright_corner) Get a rectangle shaped data out
Sheet.cut(topleft_corner, bottomright_corner) Get a rectangle shaped data out and clear them in position
Sheet.paste(topleft_corner[, rows, columns]) Paste a rectangle shaped data after a position
pyexcel.Sheet.transpose
Sheet.transpose()
pyexcel.Sheet.map
Sheet.map(custom_function)
Execute a function across all cells of the sheet
Example:
pyexcel.Sheet.region
Sheet.region(topleft_corner, bottomright_corner)
Get a rectangle shaped data out
Parameters
• topleft_corner (slice) – the top left corner of the rectangle
• bottomright_corner (slice) – the bottom right corner of the rectangle
pyexcel.Sheet.cut
Sheet.cut(topleft_corner, bottomright_corner)
Get a rectangle shaped data out and clear them in position
Parameters
• topleft_corner (slice) – the top left corner of the rectangle
• bottomright_corner (slice) – the bottom right corner of the rectangle
pyexcel.Sheet.paste
Save changes
pyexcel.Sheet.save_as
Sheet.save_as(filename, **keywords)
Save the content to a named file
Keywords may vary depending on your file type, because the associated file type employs different library.
PARAMETERS
filename: a file path
library: choose a specific pyexcel-io plugin for writing
renderer_library: choose a pyexcel parser plugin for writing
Parameters related to csv file format
for csv, fmtparams are accepted
delimiter : field separator
lineterminator : line terminator
encoding: csv specific. Specify the file encoding the csv file. For example: encoding=’latin1’. Especially,
encoding=’utf-8-sig’ would add utf 8 bom header if used in renderer, or would parse a csv with utf brom
header used in parser.
escapechar : A one-character string used by the writer to escape the delimiter if quoting is set to
QUOTE_NONE and the quotechar if doublequote is False.
quotechar : A one-character string used to quote fields containing special characters, such as the delimiter or
quotechar, or which contain new-line characters. It defaults to ‘”’
quoting : Controls when quotes should be generated by the writer and recognised by the reader. It can take on
any of the QUOTE_* constants (see section Module Contents) and defaults to QUOTE_MINIMAL.
skipinitialspace : When True, whitespace immediately following the delimiter is ignored. The default is False.
pyexcel.Sheet.save_to_memory
pyexcel.Sheet.save_to_database
pyexcel.Sheet.save_to_django_model
pyexcel.internal.sheets.Matrix
class pyexcel.internal.sheets.Matrix(array)
The internal representation of a sheet data. Each element can be of any python types
__init__(array)
Constructor
The reason a deep copy was not made here is because the data sheet could be huge. It could be costly to
copy every cell to a new memory area :param list array: a list of arrays
Methods
__init__(array) Constructor
cell_value(row, column[, new_value]) Random access to table cells
column_at(index) Gets the data at the specified column
column_range() Utility function to get column range
columns() Returns a left to right column iterator
contains(predicate) Has something in the table
Continued on next page
Attributes
pyexcel.internal.generators.SheetStream
Methods
__init__(name, payload)
get_internal_array()
to_array() Simply return the generator
Attributes
pyexcel.internal.generators.BookStream
Methods
pyexcel.internal.sheets.Row
class pyexcel.internal.sheets.Row(matrix)
Represent row of a matrix
Above column manipulation can be performed on rows similarly. This section will not repeat the same example
but show some advance usages.
__init__(matrix)
Methods
__init__(matrix)
format([row_index, formatter, format_specs]) Format a row
get_converter(theformatter) return the actual converter or a built-in converter
select(indices) Delete row indices other than specified
pyexcel.internal.sheets.Column
class pyexcel.internal.sheets.Column(matrix)
Represent columns of a matrix
__init__(matrix)
Methods
__init__(matrix)
format([column_index, formatter, format_specs]) Format a column
get_converter(theformatter) return the actual converter or a built-in converter
select(indices)
Examples
Developer’s guide
Note: As to rnd_requirements.txt, usually, it is created when a dependent library is not released. Once the dependecy
is installed (will be released), the future version of the dependency in the requirements.txt will be valid.
Although nose and doctest are both used in code testing, it is adviable that unit tests are put in tests. doctest is incor-
porated only to make sure the code examples in documentation remain valid across different development releases.
On Linux/Unix systems, please launch your tests like this:
125
pyexcel Documentation, Release 0.6.0
$ make
> test.bat
Many information that are shared across pyexcel projects, such as: this developer guide, license info, etc. are stored
in pyexcel-commons project.
When developing source plugins, it becomes necessary to have log trace available. It helps find out what goes wrong
quickly.
The basic step would be to set up logging before pyexcel import statement.
import logging
import logging.config
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.DEBUG)
import pyexcel
And if you would use a complex configuration, you can use the following code.
import logging
import logging.config
logging.config.fileConfig('log.conf')
import pyexcel
[loggers]
keys=root, sources, renderers
[handlers]
keys=consoleHandler
[formatters]
keys=custom
[logger_root]
level=INFO
handlers=consoleHandler
[logger_sources]
level=DEBUG
handlers=consoleHandler
qualname=pyexcel.sources.factory
propagate=0
[logger_renderers]
level=DEBUG
handlers=consoleHandler
qualname=pyexcel.renderers.factory
propagate=0
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=custom
args=(sys.stdout,)
[formatter_custom]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=
With pyexcel v0.5.0, the way to package it has been changed because it uses lml for all plugins.
--hidden-import pyexcel.plugins.renderers.sqlalchemy
--hidden-import pyexcel.plugins.renderers.django
--hidden-import pyexcel.plugins.renderers.excel
--hidden-import pyexcel.plugins.renderers._texttable
--hidden-import pyexcel.plugins.parsers.excel
--hidden-import pyexcel.plugins.parsers.sqlalchemy
--hidden-import pyexcel.plugins.sources.http
--hidden-import pyexcel.plugins.sources.file_input
--hidden-import pyexcel.plugins.sources.memory_input
--hidden-import pyexcel.plugins.sources.file_output
--hidden-import pyexcel.plugins.sources.output_to_memory
--hidden-import pyexcel.plugins.sources.pydata.bookdict
--hidden-import pyexcel.plugins.sources.pydata.dictsource
--hidden-import pyexcel.plugins.sources.pydata.arraysource
--hidden-import pyexcel.plugins.sources.pydata.records
--hidden-import pyexcel.plugins.sources.django
--hidden-import pyexcel.plugins.sources.sqlalchemy
--hidden-import pyexcel.plugins.sources.querysets
There are three types of plugins for pyexcel: data parser, data renderer and data source.
9.4.1 Tutorial
setupmobans pyexcel-commons
export YEHUA_FILE=$YOUR_WORK_DIRECTORY/pyexcel-commons/yehua/yehua.yml
Step 1
$ yehua
Yehua will walk you through creating a pyexcel package.
Press ^C to quit at any time.
Step 2
$ cd pyexcel-pdfr/
$ ln -s ../pyexcel-commons/ commons
$ ln -s ../setupmobans/ setupmobans
$ moban
Templating README.rst to README.rst
Templating setup.py to setup.py
Templating requirements.txt to requirements.txt
Templating NEW_BSD_LICENSE.jj2 to LICENSE
Templating MANIFEST.in.jj2 to MANIFEST.in
Templating tests/requirements.txt to tests/requirements.txt
Templating test.script.jj2 to test.sh
Templating test.script.jj2 to test.bat
Templating travis.yml.jj2 to .travis.yml
Templating gitignore.jj2 to .gitignore
Templating docs/source/conf.py.jj2 to docs/source/conf.py
Step 3 - Coding
Change log
get_{{file_type}}_stream functions from pyexcel.Sheet and pyexcel.Book were introduced since 0.4.3 but
were removed since 0.4.4. Please be advised to use save_to_memory functions, Sheet.io.{{file_type}} or
Book.io.{{file_type}}.
Filtering and formatting behavior of pyexcel.Sheet are simplified. Soft filter and soft formatter are removed.
Extra classes such as iterator, formatter, filter are removed.
Most of formatting tasks could be achieved using format() and map(). and Filtering with filter(). Formatting
and filtering on row and/or column can be found with row() and column()
sheet.filter(pe.OddRowFilter())
131
pyexcel Documentation, Release 0.6.0
>>> data = [
... ['1'],
... ['2'],
... ['3'],
... ]
>>> sheet = pe.Sheet(data)
>>> def odd_filter(row_index, _):
... return row_index % 2 == 0
>>> del sheet.row[odd_filter]
>>> sheet
pyexcel sheet:
+---+
| 2 |
+---+
sheet.apply_formatter(pe.sheets.formatters.SheetFormatter(int))
sheet.format(int)
import pyexcel.ext.xls
import pyexcel.ext.ods
import pyexcel.ext.xlsx
They are no longer needed. As long as you have pip-installed them, they will be auto-loaded. However, if you do not
want some of the plugins, please use pip to uninstall them.
What if you have your code as it is? No harm but a few warnings shown:
As in Issue 20, pyexcel-xls was used for xls and pyexcel-xlsx had to be used for xlsx. Both must co-exist due to
requirements. The workaround would failed when auto-import are enabled in v0.2.2. Hence, user of pyexcel in this
situation shall use ‘library’ parameter to all signature functions, to instruct pyexcel to use a named library for each
function call.
pyexcel.get_io was passed on from pyexcel-io. However, it is no longer exposed. Please use pyex-
cel_io.manager.RWManager.get_io if you have to.
... ]
>>> io = pyexcel.save_as(dest_file_type='csv', array=data)
>>> for line in io.readlines():
... print(line.rstrip())
1,2,3
4,5,6
import pyexcel
content = {
"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]],
"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]],
"Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]
}
w = pyexcel.BookWriter("afile.csv")
w.write_book_from_dict(content)
w.close()
Planned
added
removed
removed
fixed
1. #100, Sheet.to_dict() gets out of range error because there is only one row.
updated
added
Updated
1. embeded the enabler for pyexcel-htmlr. http source does not support text/html as mime type.
Updated
1. support saving SheetStream and BookStream to database targets. This is needed for pyexcel-webio and its
downstream projects.
Added
Updated
1. array is passed to pyexcel.Sheet as reference. it means your array data will be modified.
Removed
Updated
Updated
1. #68: regression save_to_memory() should have returned a stream instance which has been reset to zero if
possible. The exception is sys.stdout, which cannot be reset.
2. #74: Not able to handle decimal.Decimal
Removed
1. remove get_{{file_type}}_stream functions from pyexcel.Sheet and pyexcel.Book introduced since 0.4.3.
Added
1. ‘.stream’ attribute are attached to ~pyexcel.Sheet and ~pyexcel.Book to get direct access the underneath stream
in responding to file type attributes, such as sheet.xls. it helps provide a custom stream to external world, for
example, Sheet.stream.csv gives a text stream that contains csv formatted data. Book.stream.xls returns a xls
format data in a byte stream.
Updated
1. Better error reporting when an unknown parameters or unsupported file types were given to the signature func-
tions.
Updated
1. Raise exception if the incoming sheet does not have column names. In other words, only sheet with column
names could be saved to database. sheet with row names cannot be saved. The alternative is to transpose the
sheet, then name_columns_by_row and then save.
2. fix iget_records where a non-uniform content should be given, e.g. [[“x”, “y”], [1, 2], [3]], some record would
become non-uniform, e.g. key ‘y’ would be missing from the second record.
3. skip_empty_rows is applicable when saving a python data structure to another data source. For example,
if your array contains a row which is consisted of empty string, such as [‘’, ‘’, ‘’ . . . ‘’], please specify
skip_empty_rows=False in order to preserve it. This becomes subtle when you try save a python dictionary
where empty rows is not easy to be spotted.
4. #69: better documentation for save_book_as.
Updated
Added
Updated
Updated
1. #63: cannot display empty sheet(hence book with empty sheet) as texttable
Updated
Added:
1. file type setters for Sheet and Book, and its documentation
2. iget_records returns a generator for a list of records and should have better memory performance, especially
dealing with large csv files.
3. iget_array returns a generator for a list of two dimensional array and should have better memory performance,
especially dealing with large csv files.
4. Enable pagination support, and custom row renderer via pyexcel-io v0.2.3
Updated
1. Take isave_as out from save_as. Hence two functions are there for save a sheet as
2. #60: encode ‘utf-8’ if the console is of ascii encoding.
3. #59: custom row renderer
4. #56: set cell value does not work
5. pyexcel.transpose becomes pyexcel.sheets.transpose
6. iterator functions of pyexcel.Sheet were converted to generator functions
• pyexcel.Sheet.enumerate()
• pyexcel.Sheet.reverse()
• pyexcel.Sheet.vertical()
• pyexcel.Sheet.rvertical()
• pyexcel.Sheet.rows()
• pyexcel.Sheet.rrows()
• pyexcel.Sheet.columns()
• pyexcel.Sheet.rcolumns()
• pyexcel.Sheet.named_rows()
• pyexcel.Sheet.named_columns()
Removed:
1. content and out_file as function parameters to the signature functions are no longer supported.
2. SourceFactory and RendererFactory are removed
3. The following methods are removed
• pyexcel.to_array
• pyexcel.to_dict
• pyexcel.utils.to_one_dimensional_array
• pyexcel.dict_to_array
• pyexcel.from_records
• pyexcel.to_records
4. pyexcel.Sheet.filter has been re-implemented and all filters were removed:
• pyexcel.filters.ColumnIndexFilter
• pyexcel.filters.ColumnFilter
• pyexcel.filters.RowFilter
• pyexcel.filters.EvenColumnFilter
• pyexcel.filters.OddColumnFilter
• pyexcel.filters.EvenRowFilter
• pyexcel.filters.OddRowFilter
• pyexcel.filters.RowIndexFilter
• pyexcel.filters.SingleColumnFilter
• pyexcel.filters.RowValueFilter
• pyexcel.filters.NamedRowValueFilter
• pyexcel.filters.ColumnValueFilter
• pyexcel.filters.NamedColumnValueFilter
• pyexcel.filters.SingleRowFilter
5. the following functions have been removed
• add_formatter
• remove_formatter
• clear_formatters
• freeze_formatters
• add_filter
• remove_filter
• clear_filters
• freeze_formatters
6. pyexcel.Sheet.filter has been re-implemented and all filters were removed:
• pyexcel.formatters.SheetFormatter
Updated:
Updated:
Updated:
1. For python 3, do not seek 0 when saving to memory if sys.stdout is passed on. Hence, adding support for
sys.stdin and sys.stdout.
Updated:
Added:
1. add pyexcel-text file types as attributes of pyexcel.Sheet and pyexcel.Book, related to #31
2. auto import pyexcel-text if it is pip installed
Updated:
Removed:
1. pyexcel.presentation is removed. No longer the internal decorate @outsource is used. related to #31
Updated
Added
Added
Added
1. Support django
2. texttable as default renderer
Added
Added
Updated
1. Support python 3
Features:
1. read and write csv, ods, xls, xlsx and xlsm files(which are referred later as excel files)
2. various iterators for the reader
3. row and column filters for the reader
4. utilities to get array and dictionary out from excel files.
5. cookbok receipes for some common and simple usage of this library.
• genindex
• modindex
• search
145
pyexcel Documentation, Release 0.6.0
147
pyexcel Documentation, Release 0.6.0
S
save_as() (in module pyexcel), 75
save_as() (pyexcel.Book method), 95
save_as() (pyexcel.Sheet method), 117
save_book_as() (in module pyexcel), 81
save_to_database() (pyexcel.Book method), 96
save_to_database() (pyexcel.Sheet method), 117
save_to_django_model() (pyexcel.Sheet method), 118
save_to_django_models() (pyexcel.Book method), 96
save_to_memory() (pyexcel.Book method), 95
save_to_memory() (pyexcel.Sheet method), 117
set_column_at() (pyexcel.Sheet method), 106
set_named_column_at() (pyexcel.Sheet method), 108
set_named_row_at() (pyexcel.Sheet method), 108
set_row_at() (pyexcel.Sheet method), 106
Sheet (class in pyexcel), 96
sheet_names() (pyexcel.Book method), 90
SheetStream (class in pyexcel.internal.generators), 122
split_a_book() (in module pyexcel), 86
stream (pyexcel.Book attribute), 94
stream (pyexcel.Sheet attribute), 113
T
transpose() (pyexcel.Sheet method), 114
tsv (pyexcel.Book attribute), 92
tsv (pyexcel.Sheet attribute), 111
tsvz (pyexcel.Book attribute), 92
tsvz (pyexcel.Sheet attribute), 111
U
url (pyexcel.Book attribute), 91
148 Index