Single API for reading, manipulating and writing data in csv, ods, xls, xlsx and xlsm files

Overview

pyexcel - Let you focus on data, instead of file formats

https://raw.githubusercontent.com/pyexcel/pyexcel.github.io/master/images/patreon.png https://pepy.tech/badge/pyexcel/month https://img.shields.io/static/v1?label=continuous%20templating&message=%E6%A8%A1%E7%89%88%E6%9B%B4%E6%96%B0&color=blue&style=flat-square https://img.shields.io/static/v1?label=coding%20style&message=black&color=black&style=flat-square https://readthedocs.org/projects/pyexcel/badge/?version=latest

Support the project

If your company has embedded pyexcel and its components into a revenue generating product, please support me on github, patreon or bounty source to maintain the project and develop it further.

If you are an individual, you are welcome to support me too and for however long you feel like. As my backer, you will receive early access to pyexcel related contents.

And your issues will get prioritized if you would like to become my patreon as pyexcel pro user.

With your financial support, I will be able to invest a little bit more time in coding, documentation and writing interesting posts.

Known constraints

Fonts, colors and charts are not supported.

Nor to read password protected xls, xlsx and ods files.

Introduction

Feature Highlights

A list of supported file formats
file format definition
csv comma separated values
tsv tab separated values
csvz a zip file that contains one or many csv files
tsvz a zip file that contains one or many tsv files
xls a spreadsheet file format created by MS-Excel 97-2003 []
xlsx MS-Excel Extensions to the Office Open XML SpreadsheetML File Format. []
xlsm an MS-Excel Macro-Enabled Workbook file
ods open document spreadsheet
fods flat open document spreadsheet
json java script object notation
html html table of the data structure
simple simple presentation
rst rStructured Text presentation of the data
mediawiki media wiki table
[f3] quoted from whatis.com. Technical details can be found at MSDN XLS
[f4] xlsx is used by MS-Excel 2007, more information can be found at MSDN XLSX

  1. One application programming interface(API) to handle multiple data sources:
    • physical file
    • memory file
    • SQLAlchemy table
    • Django Model
    • Python data structures: dictionary, records and array
  2. One API to read and write data in various excel file formats.
  3. For large data sets, data streaming are supported. A genenerator can be returned to you. Checkout iget_records, iget_array, isave_as and isave_book_as.

Installation

You can install pyexcel via pip:

$ pip install pyexcel

or clone it and install it:

$ git clone https://github.com/pyexcel/pyexcel.git
$ cd pyexcel
$ python setup.py install

One liners

This section shows you how to get data from your excel files and how to export data to excel files in one line

Read from the excel files

Get a list of dictionaries

Suppose you want to process the following coffee data (data source coffee chart on the center for science in the public interest):

Top 5 coffeine drinks:

Coffees Serving Size Caffeine (mg)
Starbucks Coffee Blonde Roast venti(20 oz) 475
Dunkin' Donuts Coffee with Turbo Shot large(20 oz.) 398
Starbucks Coffee Pike Place Roast grande(16 oz.) 310
Panera Coffee Light Roast regular(16 oz.) 300

Let's get a list of dictionary out from the xls file:

>>> records = p.get_records(file_name="your_file.xls")

And let's check what do we have:

>>> for r in records:
...     print(f"{r['Serving Size']} of {r['Coffees']} has {r['Caffeine (mg)']} mg")
venti(20 oz) of Starbucks Coffee Blonde Roast has 475 mg
large(20 oz.) of Dunkin' Donuts Coffee with Turbo Shot has 398 mg
grande(16 oz.) of Starbucks Coffee Pike Place Roast has 310 mg
regular(16 oz.) of Panera Coffee Light Roast has 300 mg

Get two dimensional array

Instead, what if you have to use pyexcel.get_array to do the same:

>>> for row in p.get_array(file_name="your_file.xls", start_row=1):
...     print(f"{row[1]} of {row[0]} has {row[2]} mg")
venti(20 oz) of Starbucks Coffee Blonde Roast has 475 mg
large(20 oz.) of Dunkin' Donuts Coffee with Turbo Shot has 398 mg
grande(16 oz.) of Starbucks Coffee Pike Place Roast has 310 mg
regular(16 oz.) of Panera Coffee Light Roast has 300 mg

where start_row skips the header row.

Get a dictionary

You can get a dictionary too:

Now let's get a dictionary out from the spreadsheet:

>>> my_dict = p.get_dict(file_name="your_file.xls", name_columns_by_row=0)

And check what do we have:

>>> from pyexcel._compact import OrderedDict
>>> isinstance(my_dict, OrderedDict)
True
>>> for key, values in my_dict.items():
...     print(key + " : " + ','.join([str(item) for item in values]))
Coffees : Starbucks Coffee Blonde Roast,Dunkin' Donuts Coffee with Turbo Shot,Starbucks Coffee Pike Place Roast,Panera Coffee Light Roast
Serving Size : venti(20 oz),large(20 oz.),grande(16 oz.),regular(16 oz.)
Caffeine (mg) : 475,398,310,300

Please note that my_dict is an OrderedDict.

Get a dictionary of two dimensional array

Suppose you have a multiple sheet book as the following:

pyexcel:Sheet 1:

1 2 3
4 5 6
7 8 9

pyexcel:Sheet 2:

X Y Z
1 2 3
4 5 6

pyexcel:Sheet 3:

O P Q
3 2 1
4 3 2

Here is the code to obtain those sheets as a single dictionary:

>>> book_dict = p.get_book_dict(file_name="book.xls")

And check:

>>> isinstance(book_dict, OrderedDict)
True
>>> import json
>>> for key, item in book_dict.items():
...     print(json.dumps({key: item}))
{"Sheet 1": [[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]]}

Write data

Export an array

Suppose you have the following array:

>>> data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

And here is the code to save it as an excel file :

>>> p.save_as(array=data, dest_file_name="example.xls")

Let's verify it:

>>> p.get_sheet(file_name="example.xls")
pyexcel_sheet1:
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+

And here is the code to save it as a csv file :

>>> p.save_as(array=data,
...           dest_file_name="example.csv",
...           dest_delimiter=':')

Let's verify it:

>>> with open("example.csv") as f:
...     for line in f.readlines():
...         print(line.rstrip())
...
1:2:3
4:5:6
7:8:9

Export a list of dictionaries

>>> records = [
...     {"year": 1903, "country": "Germany", "speed": "206.7km/h"},
...     {"year": 1964, "country": "Japan", "speed": "210km/h"},
...     {"year": 2008, "country": "China", "speed": "350km/h"}
... ]
>>> p.save_as(records=records, dest_file_name='high_speed_rail.xls')

Export a dictionary of single key value pair

>>> henley_on_thames_facts = {
...     "area": "5.58 square meters",
...     "population": "11,619",
...     "civial parish": "Henley-on-Thames",
...     "latitude": "51.536",
...     "longitude": "-0.898"
... }
>>> p.save_as(adict=henley_on_thames_facts, dest_file_name='henley.xlsx')

Export a dictionary of single dimensonal array

>>> ccs_insights = {
...     "year": ["2017", "2018", "2019", "2020", "2021"],
...     "smart phones": [1.53, 1.64, 1.74, 1.82, 1.90],
...     "feature phones": [0.46, 0.38, 0.30, 0.23, 0.17]
... }
>>> p.save_as(adict=ccs_insights, dest_file_name='ccs.csv')

Export a dictionary of two dimensional array as a book

Suppose you want to save the below dictionary to an excel file :

>>> 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]
...          ]
...  }

Here is the code:

>>> p.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:

>>> data = OrderedDict()
>>> data.update({"Sheet 2": a_dictionary_of_two_dimensional_arrays['Sheet 2']})
>>> data.update({"Sheet 1": a_dictionary_of_two_dimensional_arrays['Sheet 1']})
>>> data.update({"Sheet 3": a_dictionary_of_two_dimensional_arrays['Sheet 3']})
>>> p.save_book_as(bookdict=data, dest_file_name="book.xls")

Let's verify its order:

>>> book_dict = p.get_book_dict(file_name="book.xls")
>>> for key, item in book_dict.items():
...     print(json.dumps({key: item}))
{"Sheet 2": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]}
{"Sheet 1": [[1, 2, 3], [4, 5, 6], [7, 8, 9]]}
{"Sheet 3": [["O", "P", "Q"], [3, 2, 1], [4, 3, 2]]}

Please notice that "Sheet 2" is the first item in the book_dict, meaning the order of sheets are preserved.

Transcoding

Note

Please note that pyexcel-cli can perform file transcoding at command line. No need to open your editor, save the problem, then python run.

The following code does a simple file format transcoding from xls to csv:

>>> p.save_as(file_name="birth.xls", dest_file_name="birth.csv")

Again it is really simple. Let's verify what we have gotten:

>>> sheet = p.get_sheet(file_name="birth.csv")
>>> sheet
birth.csv:
+-------+--------+----------+
| name  | weight | birth    |
+-------+--------+----------+
| Adam  | 3.4    | 03/02/15 |
+-------+--------+----------+
| Smith | 4.2    | 12/11/14 |
+-------+--------+----------+

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.

Let use previous example and save it as xlsx instead

>>> p.save_as(file_name="birth.xls",
...           dest_file_name="birth.xlsx") # change the file extension

Again let's verify what we have gotten:

>>> sheet = p.get_sheet(file_name="birth.xlsx")
>>> sheet
pyexcel_sheet1:
+-------+--------+----------+
| name  | weight | birth    |
+-------+--------+----------+
| Adam  | 3.4    | 03/02/15 |
+-------+--------+----------+
| Smith | 4.2    | 12/11/14 |
+-------+--------+----------+

Excel book merge and split operation in one line

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":

from pyexcel.cookbook import merge_all_to_a_book
import glob


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:

from pyexcel.cookbook import merge_all_to_a_book
import glob


merge_all_to_a_book(glob.glob("your_excel_file_directory\*.*"), "output.xls")

Split a book into single sheet files

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:

>>> from pyexcel.cookbook import split_a_book
>>> split_a_book("megabook.xls", "output.xls")
>>> import glob
>>> outputfiles = glob.glob("*_output.xls")
>>> for file in sorted(outputfiles):
...     print(file)
...
Sheet 1_output.xls
Sheet 2_output.xls
Sheet 3_output.xls

for the output file, you can specify any of the supported formats

Extract just one sheet from a book

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:

>>> from pyexcel.cookbook import extract_a_sheet_from_a_book
>>> extract_a_sheet_from_a_book("megabook.xls", "Sheet 1", "output.xls")
>>> if os.path.exists("Sheet 1_output.xls"):
...     print("Sheet 1_output.xls exists")
...
Sheet 1_output.xls exists

for the output file, you can specify any of the supported formats

Hidden feature: partial read

Most pyexcel users do not know, but other library users were requesting the similar features

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. What you may want to do is, record data from Nth line, take M records and stop. And you only want to use your memory for the M records, not for beginning part nor for the tail part.

Hence partial read feature is developed to read partial data into memory for processing.

You can paginate by row, by column and by both, hence you dictate what portion of the data to read back. But remember only row limit features help you save memory. Let's you use this feature to record data from Nth column, take M number of columns and skip the rest. You are not going to reduce your memory footprint.

Why did not I see above benefit?

This feature depends heavily on the implementation details.

pyexcel-xls (xlrd), pyexcel-xlsx (openpyxl), pyexcel-ods (odfpy) and pyexcel-ods3 (pyexcel-ezodf) will read all data into memory. Because xls, xlsx and ods file are effective a zipped folder, all four will unzip the folder and read the content in xml format in full, so as to make sense of all details.

Hence, during the partial data is been returned, the memory consumption won't differ from reading the whole data back. Only after the partial data is returned, the memory comsumption curve shall jump the cliff. So pagination code here only limits the data returned to your program.

With that said, pyexcel-xlsxr, pyexcel-odsr and pyexcel-htmlr DOES read partial data into memory. Those three are implemented in such a way that they consume the xml(html) when needed. When they have read designated portion of the data, they stop, even if they are half way through.

In addition, pyexcel's csv readers can read partial data into memory too.

Let's assume the following file is a huge csv file:

>>> import datetime
>>> import pyexcel as pe
>>> data = [
...     [1, 21, 31],
...     [2, 22, 32],
...     [3, 23, 33],
...     [4, 24, 34],
...     [5, 25, 35],
...     [6, 26, 36]
... ]
>>> pe.save_as(array=data, dest_file_name="your_file.csv")

And let's pretend to read partial data:

>>> pe.get_sheet(file_name="your_file.csv", start_row=2, row_limit=3)
your_file.csv:
+---+----+----+
| 3 | 23 | 33 |
+---+----+----+
| 4 | 24 | 34 |
+---+----+----+
| 5 | 25 | 35 |
+---+----+----+

And you could as well do the same for columns:

>>> pe.get_sheet(file_name="your_file.csv", start_column=1, column_limit=2)
your_file.csv:
+----+----+
| 21 | 31 |
+----+----+
| 22 | 32 |
+----+----+
| 23 | 33 |
+----+----+
| 24 | 34 |
+----+----+
| 25 | 35 |
+----+----+
| 26 | 36 |
+----+----+

Obvious, you could do both at the same time:

>>> 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 |
+----+----+

The pagination support is available across all pyexcel plugins.

Note

No column pagination support for query sets as data source.

Formatting while transcoding a big data file

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

Then pass it onto save_as function using row_renderer:

>>> pe.isave_as(file_name="your_file.csv",
...             row_renderer=increment_by_one,
...             dest_file_name="your_file.xlsx")

Note

If the data content is from a generator, isave_as has to be used.

We can verify if it was done correctly:

>>> pe.get_sheet(file_name="your_file.xlsx")
your_file.csv:
+---+----+----+
| 2 | 22 | 32 |
+---+----+----+
| 3 | 23 | 33 |
+---+----+----+
| 4 | 24 | 34 |
+---+----+----+
| 5 | 25 | 35 |
+---+----+----+
| 6 | 26 | 36 |
+---+----+----+
| 7 | 27 | 37 |
+---+----+----+

Stream APIs for big file : A set of two liners

When you are dealing with BIG excel files, you will want pyexcel to use constant memory.

This section shows you how to get data from your BIG excel files and how to export data to excel files in two lines at most, without eating all your computer memory.

Two liners for get data from big excel files

Get a list of dictionaries

Suppose you want to process the following coffee data again:

Top 5 coffeine drinks:

Coffees Serving Size Caffeine (mg)
Starbucks Coffee Blonde Roast venti(20 oz) 475
Dunkin' Donuts Coffee with Turbo Shot large(20 oz.) 398
Starbucks Coffee Pike Place Roast grande(16 oz.) 310
Panera Coffee Light Roast regular(16 oz.) 300

Let's get a list of dictionary out from the xls file:

>>> records = p.iget_records(file_name="your_file.xls")

And let's check what do we have:

>>> for r in records:
...     print(f"{r['Serving Size']} of {r['Coffees']} has {r['Caffeine (mg)']} mg")
venti(20 oz) of Starbucks Coffee Blonde Roast has 475 mg
large(20 oz.) of Dunkin' Donuts Coffee with Turbo Shot has 398 mg
grande(16 oz.) of Starbucks Coffee Pike Place Roast has 310 mg
regular(16 oz.) of Panera Coffee Light Roast has 300 mg

Please do not forgot the second line to close the opened file handle:

>>> p.free_resources()

Get two dimensional array

Instead, what if you have to use pyexcel.get_array to do the same:

>>> for row in p.iget_array(file_name="your_file.xls", start_row=1):
...     print(f"{row[1]} of {row[0]} has {row[2]} mg")
venti(20 oz) of Starbucks Coffee Blonde Roast has 475 mg
large(20 oz.) of Dunkin' Donuts Coffee with Turbo Shot has 398 mg
grande(16 oz.) of Starbucks Coffee Pike Place Roast has 310 mg
regular(16 oz.) of Panera Coffee Light Roast has 300 mg

Again, do not forgot the second line:

>>> p.free_resources()

where start_row skips the header row.

Data export in one liners

Export an array

Suppose you have the following array:

>>> data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

And here is the code to save it as an excel file :

>>> p.isave_as(array=data, dest_file_name="example.xls")

But the following line is not required because the data source are not file sources:

>>> # p.free_resources()

Let's verify it:

>>> p.get_sheet(file_name="example.xls")
pyexcel_sheet1:
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+

And here is the code to save it as a csv file :

>>> p.isave_as(array=data,
...            dest_file_name="example.csv",
...            dest_delimiter=':')

Let's verify it:

>>> with open("example.csv") as f:
...     for line in f.readlines():
...         print(line.rstrip())
...
1:2:3
4:5:6
7:8:9

Export a list of dictionaries

>>> records = [
...     {"year": 1903, "country": "Germany", "speed": "206.7km/h"},
...     {"year": 1964, "country": "Japan", "speed": "210km/h"},
...     {"year": 2008, "country": "China", "speed": "350km/h"}
... ]
>>> p.isave_as(records=records, dest_file_name='high_speed_rail.xls')

Export a dictionary of single key value pair

>>> henley_on_thames_facts = {
...     "area": "5.58 square meters",
...     "population": "11,619",
...     "civial parish": "Henley-on-Thames",
...     "latitude": "51.536",
...     "longitude": "-0.898"
... }
>>> p.isave_as(adict=henley_on_thames_facts, dest_file_name='henley.xlsx')

Export a dictionary of single dimensonal array

>>> ccs_insights = {
...     "year": ["2017", "2018", "2019", "2020", "2021"],
...     "smart phones": [1.53, 1.64, 1.74, 1.82, 1.90],
...     "feature phones": [0.46, 0.38, 0.30, 0.23, 0.17]
... }
>>> p.isave_as(adict=ccs_insights, dest_file_name='ccs.csv')
>>> p.free_resources()

Export a dictionary of two dimensional array as a book

Suppose you want to save the below dictionary to an excel file :

>>> 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]
...          ]
...  }

Here is the code:

>>> p.isave_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:

>>> from pyexcel._compact import OrderedDict
>>> data = OrderedDict()
>>> data.update({"Sheet 2": a_dictionary_of_two_dimensional_arrays['Sheet 2']})
>>> data.update({"Sheet 1": a_dictionary_of_two_dimensional_arrays['Sheet 1']})
>>> data.update({"Sheet 3": a_dictionary_of_two_dimensional_arrays['Sheet 3']})
>>> p.isave_book_as(bookdict=data, dest_file_name="book.xls")
>>> p.free_resources()

Let's verify its order:

>>> import json
>>> book_dict = p.get_book_dict(file_name="book.xls")
>>> for key, item in book_dict.items():
...     print(json.dumps({key: item}))
{"Sheet 2": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]}
{"Sheet 1": [[1, 2, 3], [4, 5, 6], [7, 8, 9]]}
{"Sheet 3": [["O", "P", "Q"], [3, 2, 1], [4, 3, 2]]}

Please notice that "Sheet 2" is the first item in the book_dict, meaning the order of sheets are preserved.

File format transcoding on one line

Note

Please note that the following file transcoding could be with zero line. Please install pyexcel-cli and you will do the transcode in one command. No need to open your editor, save the problem, then python run.

The following code does a simple file format transcoding from xls to csv:

>>> import pyexcel
>>> p.save_as(file_name="birth.xls", dest_file_name="birth.csv")

Again it is really simple. Let's verify what we have gotten:

>>> sheet = p.get_sheet(file_name="birth.csv")
>>> sheet
birth.csv:
+-------+--------+----------+
| name  | weight | birth    |
+-------+--------+----------+
| Adam  | 3.4    | 03/02/15 |
+-------+--------+----------+
| Smith | 4.2    | 12/11/14 |
+-------+--------+----------+

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.

Let use previous example and save it as xlsx instead

>>> import pyexcel
>>> p.isave_as(file_name="birth.xls",
...            dest_file_name="birth.xlsx") # change the file extension

Again let's verify what we have gotten:

>>> sheet = p.get_sheet(file_name="birth.xlsx")
>>> sheet
pyexcel_sheet1:
+-------+--------+----------+
| name  | weight | birth    |
+-------+--------+----------+
| Adam  | 3.4    | 03/02/15 |
+-------+--------+----------+
| Smith | 4.2    | 12/11/14 |
+-------+--------+----------+

Available Plugins

A list of file formats supported by external plugins
Package name Supported file formats Dependencies
pyexcel-io csv, csvz [1], tsv, tsvz [2]  
pyexcel-xls xls, xlsx(read only), xlsm(read only) xlrd, xlwt
pyexcel-xlsx xlsx openpyxl
pyexcel-ods3 ods pyexcel-ezodf, lxml
pyexcel-ods ods odfpy
Dedicated file reader and writers
Package name Supported file formats Dependencies
pyexcel-xlsxw xlsx(write only) XlsxWriter
pyexcel-libxlsxw xlsx(write only) libxlsxwriter
pyexcel-xlsxr xlsx(read only) lxml
pyexcel-xlsbr xlsb(read only) pyxlsb
pyexcel-odsr read only for ods, fods lxml
pyexcel-odsw write only for ods loxun
pyexcel-htmlr html(read only) lxml,html5lib
pyexcel-pdfr pdf(read only) camelot

Plugin shopping guide

Since 2020, all pyexcel-io plugins have dropped the support for python version lower than 3.6. If you want to use any python verions, please use pyexcel-io and its plugins version lower than 0.6.0.

Except csv files, xls, xlsx and ods files are a zip of a folder containing a lot of xml files

The dedicated readers for excel files can stream read

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').

Other data renderers
Package name Supported file formats Dependencies Python versions
pyexcel-text write only:rst, mediawiki, html, latex, grid, pipe, orgtbl, plain simple read only: ndjson r/w: json tabulate 2.6, 2.7, 3.3, 3.4 3.5, 3.6, pypy
pyexcel-handsontable handsontable in html handsontable same as above
pyexcel-pygal svg chart pygal 2.7, 3.3, 3.4, 3.5 3.6, pypy
pyexcel-sortable sortable table in html csvtotable same as above
pyexcel-gantt gantt chart in html frappe-gantt except pypy, same as above

Footnotes

[1] zipped csv file
[2] zipped tsv file

Acknowledgement

All great work have been done by odf, ezodf, xlrd, xlwt, tabulate and other individual developers. This library unites only the data access code.

License

New BSD License

Comments
  • Even if the format is a string it is displayed as a float

    Even if the format is a string it is displayed as a float

    This a bug of display and very annoying, since even if a number (like serial number for example) is wirtten as a text into a table it is still displayed as a float,

    Example:

    '>>> ReportWorkbook = pe.get_book(file_name=rep_name) '>>> ReportWorkbook['Infos'] Sheet Name: Infos +-----------------+------------------+ | Date | 2016-03-31 10:59 | +-----------------+------------------+ | Model name | XS360_EU | +-----------------+------------------+ | Time by X | 60 | +-----------------+------------------+ | Product A | 123 | +-----------------+------------------+ | Product B | 4.567e+15 | +-----------------+------------------+ | Bandwidth (UDP) | N/A | +-----------------+------------------+ | Other infos | N/A | +-----------------+------------------+ '>>> ReportWorkbook['Infos'].column[1] ['2016-03-31 10:59', 'XS360_EU', 60.0, '0123', '04566651561653122', 'N/A', 'N/A']

    As seen above the serial numbers of products A and B are 0123 and 04566651561653122 are stocked as a text (string), however. Whend displayed with print they are displayed as a float so we se the first '0' disappear and 4.567e+15 insetead of 04566651561653122

    bug 
    opened by Navis-Raven 34
  • xls does not save itself as ods files do

    xls does not save itself as ods files do

    Let's consider thoose two codes :

    >>> import os, sys
    >>> import pyexcel as pe
    >>> import pyexcel.ext.ods3
    >>> from pyexcel_ods3 import get_data, save_data
    >>> al = pe.get_book(file_name="wb.ods")
    >>> al
    Sheet Name: Feuil1
    +---+-------+
    | A | B     |
    +---+-------+
    | 1 | alpha |
    +---+-------+
    | 2 | beta  |
    +---+-------+
    | 3 | gamma |
    +---+-------+
    >>> al.save_as("tst.ods")
    >>> 
    

    With the ods file everything is OK

    And now this one:

    >>> import os
    >>> import sys
    >>> import pyexcel as pe
    >>> import pyexcel.ext.xls
    >>> al = pyexcel.get_book(file_name="wb.xls")
    >>> al
    Sheet Name: Feuil1
    +---+-------+
    | A | B     |
    +---+-------+
    | 1 | alpha |
    +---+-------+
    | 2 | beta  |
    +---+-------+
    | 3 | gamma |
    +---+-------+
    >>> al.save_as("tst.xls")
    Traceback (most recent call last):
      File "<pyshell#14>", line 1, in <module>
        al.save_as("tst.xls")
    etc, etc, etc....
    AttributeError: 'dict_items' object has no attribute 'sort'
    

    Why by using the same coding we does not have the same success, we have an error with xls

    opened by Navis-Raven 21
  • Different displays between when opening the file and directly in v0.2.1

    Different displays between when opening the file and directly in v0.2.1

    I remarked something strange in this version 0.2.1.

    When we put a number as an int, if we print the table, it displays the number as an int.

    But, if we save the file then reopenning it, displays it as a float. It is strange.

    Look at the following code:

    >>> import pyexcel as pe
    >>> import pyexcel.ext.ods3
    >>> a=[[60, 50.0, '120']]
    >>> s=pyexcel.get_sheet(array=a)
    >>> s
    Sheet Name: pyexcel_sheet1
    +----+------+-----+
    | 60 | 50.0 | 120 |
    +----+------+-----+
    >>> s.save_as("sr.ods")
    >>> o = pe.get_sheet(file_name="sr.ods")
    >>> o
    Sheet Name: pyexcel_sheet1
    +------+------+-----+
    | 60.0 | 50.0 | 120 |
    +------+------+-----+
    >>> 
    

    Before saving into a file 60 is displayed as an int, and after saving into a file it is displayed as a float (60.0).

    enhancement 
    opened by Navis-Raven 20
  • CSV UTF-8 encoding

    CSV UTF-8 encoding

    Hi!

    First of great package, thank you!

    I encountered a problem with csv UTF-8 encoding when converting a xlsx file to csv.

    If I follow the recommended way from the docs:

    import pyexcel
    import pyexcel.ext.xlsx
    
    
    pyexcel.save_as(file_name="example.xlsx", dest_file_name="exmaple.csv")
    

    and the xlsx file is UTF-8, the dest_file is not. Even if I add encoding="UTF-8" nothing changes.

    The only workaround I found is to use the CSV standard library:

    import csv
    import pyexcel
    import pyexcel.ext.xlsx
    
    
    sheet = pe.get_sheet(file_name="example.xlsx")
    with open("example.csv", "w", newline="", encoding="UTF-8") as csvfile:
        writer = csv.writer(csvfile)
        for row in sheet:
            writer.writerow(row)
        csvfile.close()
    
    opened by dasdachs 19
  • isave_as not writing periodically for XLS and XLSX formats

    isave_as not writing periodically for XLS and XLSX formats

    I'm using isave_as to save large datasets to files. When using the CSV format, the file is being built progressively, which makes it very memory efficient. When using XLS or XLSX, it seems to store everything in memory before dumping it to the file all at once, which requires the whole dataset to fit in memory.

    I suppose it's trickier to write as you go for these formats, but I'm wondering if it would still be possible?

    opened by PLPeeters 18
  • dynamically resize the table matrix on set_value

    dynamically resize the table matrix on set_value

    I will conform to pr checklist later.

    here is a use case:

    sheet=pyexcel.Sheet()
    sheet[1,1] = "JO"
    sheet["AA1"] = "test"
    

    that leads to an index error. I think it is a valid use case to set arbitrary cells at random positions?

    This pr adds arguments to uniform so we can make an array of min_width and min_height

    
    ---------------------------------------------------------------------------
    IndexError                                Traceback (most recent call last)
    <ipython-input-2-df6d362a346f> in <module>
          1 sheet=pyexcel.Sheet()
          2 sheet[1,1] = "JO"
    ----> 3 sheet["AA1"] = "test"
    
    ~/dev/pyexcel/pyexcel/sheet.py in __setitem__(self, aset, c)
        607             self.cell_value(row, column, c)
        608         else:
    --> 609             Matrix.__setitem__(self, aset, c)
        610 
        611     def __len__(self):
    
    ~/dev/pyexcel/pyexcel/internal/sheets/matrix.py in __setitem__(self, aset, cell_value)
        467         elif isinstance(aset, str):
        468             row, column = utils.excel_cell_position(aset)
    --> 469             return self.cell_value(row, column, cell_value)
        470         else:
        471             raise IndexError
    
    ~/dev/pyexcel/pyexcel/internal/sheets/matrix.py in cell_value(self, row, column, new_value)
         94                 raise IndexError("Index out of range")
         95             else:
    ---> 96                 self.paste((row, column), [[new_value]])
         97 
         98     def row_at(self, index):
    
    ~/dev/pyexcel/pyexcel/internal/sheets/matrix.py in paste(self, topleft_corner, rows, columns)
        405         """
        406         if rows:
    --> 407             self._paste_rows(topleft_corner, rows)
        408         elif columns:
        409             self._paste_columns(topleft_corner, columns)
    
    ~/dev/pyexcel/pyexcel/internal/sheets/matrix.py in _paste_rows(self, topleft_corner, rows)
        427             set_index = starting_row + index
        428             if set_index < number_of_rows:
    --> 429                 self._set_row_at(set_index, row, starting=topleft_corner[1])
        430             else:
        431                 real_row = [constants.DEFAULT_NA] * topleft_corner[1] + row
    
    ~/dev/pyexcel/pyexcel/internal/sheets/matrix.py in _set_row_at(self, row_index, data_array, starting)
        153             self.__width, self.__array = uniform(self.__array)
        154         else:
    --> 155             raise IndexError(constants.MESSAGE_INDEX_OUT_OF_RANGE)
        156 
        157     def _extend_row(self, row):
    

    With your PR, here is a check list:

    • [ ] Has test cases written?
    • [ ] Has all code lines tested?
    • [ ] Has make format been run?
    • [ ] Please update CHANGELOG.yml(not CHANGELOG.rst)
    • [ ] Passes all Travis CI builds
    • [ ] Has fair amount of documentation if your change is complex
    • [x] Agree on NEW BSD License for your contribution
    opened by hiaselhans 16
  • save_as from xlsx to csv: error array index out of range

    save_as from xlsx to csv: error array index out of range

    #!/usr/bin/env python
    import pyexcel
    import os
    from pyexcel.ext import xlsx
    from pyexcel.ext import xls
    
    pyexcel.save_as(file_name="Test2.xlsx", dest_file_name="Test2.csv")
    

    When I tried to use the code above to save the attached file as a csv file in python 3, the following error occurred: IndexError: array index out of range Test2.xlsx

    opened by Rehgan 16
  • Fix typo in tutorial_data_conversion.rst

    Fix typo in tutorial_data_conversion.rst

    By the way, could you add some example code on how to exactly open a multiple sheet Excel workbook and save its sheets to CSV files? It's not really clear to me what the right incantation is for pyexcel.save_book_as.

    I'm currently using pyexcel.save_as(file_name=inputfilepath, dest_file_name=outputfilepath), but that only saves the first sheet.

    opened by rmzelle 15
  • File type not supported

    File type not supported

    Following the example from the README:

    >>> sheet = p.get_sheet(file_name="in.xlsm")
    >>> sheet.save_as("test.html", display_length=10)
    

    I end up with an error:

    constants.FILE_TYPE_NOT_SUPPORTED_FMT % (file_type, action))
    pyexcel.exceptions.FileTypeNotSupported: File type 'html' is not supported for write.
    

    The only difference I'm aware of is the input file format, but the error message that is surfaced doesn't mention anything to do with this. Any ideas what might be wrong?

    opened by mtn 13
  • AttributeError: module 'pyexcel' has no attribute 'save_as'

    AttributeError: module 'pyexcel' has no attribute 'save_as'

    Hello I'm using pyexcel on two platforms, OSX and Linux. My code works on OSX but not on Linux. On Linux, this error is simply reproduced by:

    root@510fc9830b71:~/project# python3.6
    Python 3.6.1 (default, Apr  7 2017, 01:47:28) 
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pyexcel
    >>> pyexcel.save_as()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: module 'pyexcel' has no attribute 'save_as'
    

    Based on our CircleCI logs, this problem started appearing in the last 13 days. Thanks for your help Arthur

    On OSX I have these Python packages imported:

    $ pip list --format=columns
    Package                                Version    
    -------------------------------------- -----------
    abduct                                 2.0.1      
    alabaster                              0.7.9      
    appnope                                0.1.0      
    args                                   0.1.0      
    arrow                                  0.8.0      
    astroid                                1.4.8      
    attrdict                               2.0.0      
    autopep8                               1.2.4      
    Babel                                  2.3.4      
    biopython                              1.68       
    bleach                                 2.0.0      
    capturer                               2.1.1      
    cement                                 2.10.2     
    cffi                                   1.8.3      
    clint                                  0.5.1      
    cobra                                  0.4.1      
    codeclimate-test-reporter              0.1.2      
    configobj                              5.0.6      
    configparser                           3.5.0      
    contextlib2                            0.5.4      
    coverage                               4.2        
    coveralls                              1.1        
    cryptography                           1.5.2      
    cycler                                 0.10.0     
    decorator                              4.0.11     
    docopt                                 0.6.2      
    docutils                               0.12       
    entrypoints                            0.2.2      
    enum34                                 1.1.6      
    et-xmlfile                             1.0.1      
    flake8                                 3.0.4      
    ftputil                                3.3.1      
    future                                 0.15.2     
    gitdb                                  0.6.4      
    GitPython                              2.0.8      
    graphviz                               0.5.1      
    html5lib                               0.999999999
    idna                                   2.1        
    imagesize                              0.7.1      
    inflect                                0.2.5      
    ipykernel                              4.5.2      
    ipython                                5.3.0      
    ipython-genutils                       0.2.0      
    ipywidgets                             6.0.0      
    isort                                  4.2.5      
    jdcal                                  1.2        
    Jinja2                                 2.8        
    jsonschema                             2.6.0      
    junit2html                             4          
    jupyter                                1.0.0      
    jupyter-client                         5.0.0      
    jupyter-console                        5.1.0      
    jupyter-core                           4.3.0      
    lazy-object-proxy                      1.2.2      
    linecache2                             1.0.0      
    log                                    2016.10.12 
    lxml                                   3.6.4      
    MarkupSafe                             0.23       
    matplotlib                             1.5.3      
    mccabe                                 0.5.2      
    mistune                                0.7.4      
    mock                                   2.0.0      
    mpmath                                 0.19       
    natsort                                5.0.1      
    nbconvert                              5.1.1      
    nbformat                               4.3.0      
    networkx                               1.11       
    nose                                   1.3.7      
    nose2unitth                            0.0.10     
    notebook                               4.4.1      
    numpy                                  1.11.1     
    obj-model                              0.0.4      
    openpyxl                               2.3.5      
    optlang                                1.2.1      
    pandocfilters                          1.4.1      
    paramiko                               2.0.2      
    pbr                                    2.0.0      
    pep8                                   1.7.0      
    pexpect                                4.2.1      
    pgmpy                                  0.1.2      
    pickleshare                            0.7.4      
    Pint                                   0.8.1      
    pip                                    9.0.1      
    pkginfo                                1.3.2      
    pockets                                0.3        
    progress                               1.2        
    prompt-toolkit                         1.0.13     
    ptyprocess                             0.5.1      
    py                                     1.4.31     
    pyasn1                                 0.1.9      
    pycodestyle                            2.0.0      
    pycparser                              2.16       
    pyexcel                                0.4.2      
    pyexcel-io                             0.3.1      
    pyflakes                               1.2.3      
    pygit2                                 0.25.0     
    Pygments                               2.1.3      
    pylint                                 1.6.4      
    pyparsing                              2.1.9      
    pysftp                                 0.2.9      
    pytest                                 3.0.4.dev0 
    pytest-cov                             2.5.1      
    python-dateutil                        2.5.3      
    python-libsbml                         5.13.0     
    python-libsedml                        0.4.1      
    pytz                                   2016.6.1   
    PyYAML                                 3.12       
    pyzmq                                  16.0.2     
    qtconsole                              4.2.1      
    qualname                               0.1.0      
    recordtype                             1.1        
    requests                               2.11.1     
    requests-toolbelt                      0.7.0      
    robpol86-sphinxcontrib-googleanalytics 0.1        
    scikit-learn                           0.18.1     
    scipy                                  0.18.0     
    setuptools                             28.6.0     
    simplegeneric                          0.8.1      
    six                                    1.10.0     
    smmap                                  0.9.0      
    snowballstemmer                        1.2.1      
    Sphinx                                 1.4.8      
    sphinx-rtd-theme                       0.1.9      
    sphinxcontrib-napoleon                 0.5.3      
    SQLAlchemy                             1.1.10     
    stringcase                             1.0.6      
    swiglpk                                1.4.3      
    sympy                                  1.0        
    terminado                              0.6        
    test                                   2.3.4.5    
    testpath                               0.3        
    texttable                              0.8.7      
    tornado                                4.4.2      
    traceback2                             1.4.0      
    traitlets                              4.3.2      
    twine                                  1.8.1      
    unittest2                              1.1.0      
    unitth                                 0.0.8      
    wc-lang                                0.0.1      
    wc-utils                               0.0.1a4    
    wcwidth                                0.1.7      
    weakreflist                            0.4        
    webencodings                           0.5        
    wheel                                  0.29.0     
    widgetsnbextension                     2.0.0      
    wrapt                                  1.10.8     
    

    And on Linux I have these:

    root@510fc9830b71:~/project# pip list
    abduct (2.0.1)
    alabaster (0.7.10)
    asn1crypto (0.22.0)
    attrdict (2.0.0)
    Babel (2.4.0)
    beautifulsoup4 (4.5.3)
    biopython (1.69)
    bs4 (0.0.1)
    capturer (2.4)
    cement (2.10.2)
    certifi (2017.4.17)
    cffi (1.10.0)
    chardet (3.0.4)
    cobra (0.5.4)
    codeclimate-test-reporter (0.2.3)
    configobj (5.0.6)
    configparser (3.5.0)
    contextlib2 (0.5.5)
    coverage (4.3.4)
    coveralls (1.1)
    cryptography (1.8.1)
    cycler (0.10.0)
    Django (1.10.2)
    docopt (0.6.2)
    docutils (0.13.1)
    docx (0.2.4)
    enum34 (1.1.6)
    et-xmlfile (1.0.1)
    ete3 (3.0.0b35)
    functools32 (3.2.3.post2)
    future (0.16.0)
    google-api-python-client (1.6.2)
    httplib2 (0.10.3)
    humanfriendly (3.8)
    idna (2.5)
    imagesize (0.7.1)
    inflect (0.2.5)
    ipaddress (1.0.18)
    jdcal (1.3)
    Jinja2 (2.9.6)
    junit2html (4)
    Karr-Lab-build-utils (0.0.13, /root/project/src/karr-lab-build-utils)
    lml (0.0.1)
    log (2016.10.12)
    lxml (3.7.3)
    MarkupSafe (1.0)
    matplotlib (2.0.0)
    monotonic (1.3)
    mpmath (0.19)
    MySQL-python (1.2.5)
    natsort (5.0.3)
    nose (1.3.7)
    nose2unitth (0.0.12)
    numpy (1.13.0)
    oauth2client (4.0.0)
    obj-model (0.0.4)
    odfpy (1.3.4)
    olefile (0.44)
    openbabel (2.4.1)
    openpyxl (2.4.8)
    packaging (16.8)
    Pillow (4.1.0)
    Pint (0.8.1)
    pip (9.0.1)
    progress (1.2)
    py (1.4.34)
    pyasn1 (0.2.3)
    pyasn1-modules (0.0.8)
    pycparser (2.17)
    pyexcel (0.5.0)
    pyexcel-io (0.4.1)
    pyexcel-xls (0.4.0)
    pygit2 (0.25.0)
    Pygments (2.2.0)
    pyOpenSSL (16.2.0)
    pyparsing (2.2.0)
    PyPDF2 (1.26.0)
    pytest (3.1.2)
    python-dateutil (2.6.0)
    python-docx (0.8.6)
    python-libsbml (5.15.0)
    python-libsedml (0.4.1)
    pytz (2017.2)
    PyYAML (3.12)
    qualname (0.1.0)
    recordtype (1.1)
    requests (2.18.1)
    robpol86-sphinxcontrib-googleanalytics (0.1)
    rsa (3.4.2)
    rtf2xml (1.33)
    scipy (0.19.0)
    setuptools (36.0.1)
    six (1.10.0)
    snowballstemmer (1.2.1)
    Sphinx (1.6.3)
    sphinx-rtd-theme (0.2.4)
    sphinxcontrib-websupport (1.0.1)
    stringcase (1.0.6)
    subprocess32 (3.2.7)
    sympy (1.0)
    texttable (0.9.1)
    typing (3.6.1)
    uritemplate (3.0.0)
    urllib3 (1.21.1)
    wc-lang (0.0.1, /root/project)
    wc-utils (0.0.1a5)
    weakreflist (0.4)
    xlrd (1.0.0)
    xlwt (1.2.0)
    
    opened by artgoldberg 13
  • pyinstaller packaging: pyexcel.exceptions.UnknownParameters file_name

    pyinstaller packaging: pyexcel.exceptions.UnknownParameters file_name

    I run Python 3.5.3 (64 bit) on Windows 7 after making exe with pyinstaller My script stops working (file and path are checked to be correct), but I got that exception. pyexcel.exceptions.UnknownParameters: Please check if there were typos in function parameters: {'file_name': 'C:\py\input_data.xls'}. Otherwise unrecognized parameters were given.

    Here is function call filename = r'C:\py\input_data.xls' if os.path.exists(filename): sheet = pyexcel.get_sheet(file_name=filename)

    opened by georgesimeo 13
  • pylint fixes

    pylint fixes

    python 3 changes, simplifications, tidy of imports

    With your PR, here is a check list:

    • [N/A ] Has test cases written?
    • [ Y] Has all code lines tested?
    • [ ] Has make format been run?
    • [ ] Please update CHANGELOG.yml(not CHANGELOG.rst)
    • [ ] Has fair amount of documentation if your change is complex
    • [Y] Agree on NEW BSD License for your contribution
    opened by marksmayo 0
  • pyexcel assumes dest_file_name is a str, does not tolerate pathlib.Path

    pyexcel assumes dest_file_name is a str, does not tolerate pathlib.Path

    During keyword ingestion in: https://github.com/pyexcel/pyexcel/blob/d8b965060889708ed7f718139076a71fe8c25490/pyexcel/core.py#L86 pyexcel assumes dest_file_name is a str, does not tolerate pathlib.Path

    Here's an example:

    >>> pyexcel.save_as(array=data, dest_file_name=path)
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Data\venv\tablite310\lib\site-packages\pyexcel\core.py", line 82, in save_as
        return sources.save_sheet(sheet, **dest_keywords)
      File "C:\Data\venv\tablite310\lib\site-packages\pyexcel\internal\core.py", line 46, in save_sheet
        a_source = SOURCE.get_writable_source(**keywords)
      File "C:\Data\venv\tablite310\lib\site-packages\pyexcel\internal\source_plugin.py", line 91, in get_writable_source
        return self.get_a_plugin(
      File "C:\Data\venv\tablite310\lib\site-packages\pyexcel\internal\source_plugin.py", line 69, in get_a_plugin
        source_cls = self.load_me_now(
      File "C:\Data\venv\tablite310\lib\site-packages\pyexcel\internal\source_plugin.py", line 41, in load_me_now
        if source.is_my_business(action, **keywords):
      File "C:\Data\venv\tablite310\lib\site-packages\pyexcel\plugins\__init__.py", line 56, in is_my_business
        raise IOError("Unsupported file type")
    OSError: Unsupported file type
    

    ^--- This is not a useful error message for this input ---v

    >>> path
    WindowsPath('C:/Users/madsenbj/AppData/Local/Temp/junk_test/myfile.xlsx')
    >>> pyexcel.save_as(array=data, dest_file_name=str(path))
    >>>
    

    If anything it should be TypeError(f"expected str, got {type(dest_file_name)}")

    opened by root-11 0
  • Add tqdm progressbar to BookStream and SheetStream [feature request]

    Add tqdm progressbar to BookStream and SheetStream [feature request]

    Would it be possible to add a progress bar (tqdm preferred) to load & save sheet/book?

    I often see 400-500Mb xlsx books and it does take a little while to read them.

    At a quick glance it seems like a relatively simple wrapping about get_stream for load book and sheet near this:

    https://github.com/pyexcel/pyexcel/blob/d8b965060889708ed7f718139076a71fe8c25490/pyexcel/internal/core.py#L29

    For save I couldn't quite figure the call hierarchy out.

    opened by root-11 0
  • `file_name` argument supports `pathlib.Path`

    `file_name` argument supports `pathlib.Path`

    Description

    I prefer Path rather than the path string. Path operates path string more friendly (such as connecting paths via /). And Path get more and more popular.

    Whether pyexcel would support Path?

    Example

    from pathlib import Path
    
    import pyexcel as pe
    
    file = Path("demo.xlsx")
    pe.get_sheet(file_name=file)
    # raise OSError: Unsupported file type
    
    pe.get_sheet(file_name=file.as_posix())
    # work, `file_name` only receives string type
    

    Environment

    • Win10 21H2
    • python 3.9.13.final.0
    • pyexcel 0.7.0
    • pyexcel-io 0.6.6
    • pyexcel-xls 0.6.2
    opened by Zeroto521 0
  • How can I maintain column headers when adding all sheets to a book?

    How can I maintain column headers when adding all sheets to a book?

    Hi.

    I love to use pyexcel. Thanks. I have a question. Just now I realized column headers are gone after some processes with a single sheet, which has column headers assigned by sheet.name_columns_by_row(0). When I save a file with a single sheet, column headers are ok, but when I save a file as a book after adding, they are gone.

    for example.. after inputting header names and data into each sheet..

    sheet1.name_columns_by_row(0) sheet2.name_columns_by_row(0)

    sheet1: +------------+--------+--------+ | column1 | column2| column3 | +======+======+=====+ | 1 | 2 | 3 | +------------+--------+--------+

    sheet2: +------------+--------+--------+ | columnA | columnB| columnC | +======+======+=====+ | A | B | C | +------------+--------+--------+

    book1 = sheet1 + sheet2 book1. save_as(book1_filename)

    I naturally thought every sheet in book1 must have column headers, but the result is like below..

    sheet1: +------------+--------+--------+ | 1 | 2 | 3 | +------------+--------+--------+

    sheet2: +------------+--------+--------+ | A | B | C | +------------+--------+--------+

    when I save each sheet as a separate file, the headers are ok. So if I use merge_all_to_a_book, it works ok in this case, the headers are not disappeared but this is very complex. moreover, I have to change sheet names. This is not a beautiful solution.

    Please let me know what I should do to maintain column headers when I add sheets. I have to use this book at the next process, but it failed because they don't have column names.

    opened by unique0ne0 0
Releases(v0.7.0)
Python Module for Tabular Datasets in XLS, CSV, JSON, YAML, &c.

Tablib: format-agnostic tabular dataset library _____ ______ ___________ ______ __ /_______ ____ /_ ___ /___(_)___ /_ _ __/_ __ `/__ _

Jazzband 4.2k Dec 30, 2022
Library to create spreadsheet files compatible with MS Excel 97/2000/XP/2003 XLS files, on any platform.

xlwt This is a library for developers to use to generate spreadsheet files compatible with Microsoft Excel versions 95 to 2003. The package itself is

null 1k Dec 24, 2022
PyExcelerate - Accelerated Excel XLSX Writing Library for Python 2/3

PyExcelerate Accelerated Excel XLSX writing library for Python master: dev: test coverage: Authors: Kevin Wang and Kevin Zhang Copyright 2015 Kevin Wa

null 448 Dec 28, 2022
A Python module for creating Excel XLSX files.

XlsxWriter XlsxWriter is a Python module for writing files in the Excel 2007+ XLSX file format. XlsxWriter can be used to write text, numbers, formula

John McNamara 3.1k Dec 29, 2022
Xiaobo Zhang 30 Jan 8, 2023
Upload an Excel/CSV file ( < 200 MB) and produce a short summary of the data.

Data-Analysis-Report Deployed App 1. What is this app? Upload an excel/csv file and produce a summary report of the data. 2. Where to upload? How to p

Easwaran T H 0 Feb 26, 2022
A suite of utilities for converting to and working with CSV, the king of tabular file formats.

csvkit is a suite of command-line tools for converting to and working with CSV, the king of tabular file formats. It is inspired by pdftk, GDAL and th

wireservice 5.2k Dec 31, 2022
Reads Data from given Excel File and exports Single PDFs and a complete PDF grouped by Gateway

E-Shelter Excel2QR Reads Data from given Excel File and exports Single PDFs and a complete PDF grouped by Gateway Features Reads Excel 2021 Export Sin

Stefan Knaak 1 Nov 13, 2021
ExcelPeek is a tool designed to help investigate potentially malicious Microsoft Excel files.

ExcelPeek is a tool designed to help investigate potentially malicious Microsoft Excel files.

James Slaughter 37 Apr 16, 2022
xlwings is a BSD-licensed Python library that makes it easy to call Python from Excel and vice versa. It works with Microsoft Excel on Windows and macOS. Sign up for the newsletter or follow us on twitter via

xlwings - Make Excel fly with Python! xlwings CE xlwings CE is a BSD-licensed Python library that makes it easy to call Python from Excel and vice ver

xlwings 2.5k Jan 6, 2023
ObjTables: Tools for creating and reusing high-quality spreadsheets

ObjTables: Tools for creating and reusing high-quality spreadsheets ObjTables is a toolkit which makes it easy to use spreadsheets (e.g., XLSX workboo

Karr whole-cell modeling lab 7 Jun 14, 2021
Transpiler for Excel formula like language to Python. Support script and module mode

Transpiler for Excel formula like language to Python. Support script and module mode (formulas are functions).

Edward Villegas-Pulgarin 1 Dec 7, 2021
A flask extension using pyexcel to read, manipulate and write data in different excel formats: csv, ods, xls, xlsx and xlsm.

Flask-Excel - Let you focus on data, instead of file formats Support the project If your company has embedded pyexcel and its components into a revenu

null 247 Dec 27, 2022
Exe-to-xlsm - Simple script to create VBscript of exe and inject to xlsm

?? Exe To Office Executable file injection to Office documents: .xlsm, .docm, .p

null 3 Jan 25, 2022
According to the received excel file (.xlsx,.xlsm,.xltx,.xltm), it converts to word format with a given table structure and formatting

According to the received excel file (.xlsx,.xlsm,.xltx,.xltm), it converts to word format with a given table structure and formatting

Diakonov Andrey 2 Feb 18, 2022
Python Module for Tabular Datasets in XLS, CSV, JSON, YAML, &c.

Tablib: format-agnostic tabular dataset library _____ ______ ___________ ______ __ /_______ ____ /_ ___ /___(_)___ /_ _ __/_ __ `/__ _

Jazzband 4.2k Dec 30, 2022
Scrapes mcc-mnc.com and outputs 3 files with the data (JSON, CSV & XLSX)

mcc-mnc.com-webscraper Scrapes mcc-mnc.com and outputs 3 files with the data (JSON, CSV & XLSX) A Python script for web scraping mcc-mnc.com Link: mcc

Anton Ivarsson 1 Nov 7, 2021
Library to create spreadsheet files compatible with MS Excel 97/2000/XP/2003 XLS files, on any platform.

xlwt This is a library for developers to use to generate spreadsheet files compatible with Microsoft Excel versions 95 to 2003. The package itself is

null 1k Dec 24, 2022
borb is a library for reading, creating and manipulating PDF files in python.

borb is a library for reading, creating and manipulating PDF files in python.

Joris Schellekens 2.9k Jan 1, 2023
PyExcelerate - Accelerated Excel XLSX Writing Library for Python 2/3

PyExcelerate Accelerated Excel XLSX writing library for Python master: dev: test coverage: Authors: Kevin Wang and Kevin Zhang Copyright 2015 Kevin Wa

null 448 Dec 28, 2022