Skip to content

Commit

Permalink
update documentation on examples
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Jan 23, 2017
1 parent 02263d5 commit 689f21c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 33 deletions.
11 changes: 5 additions & 6 deletions examples/basics/convert_xls_to_xlsx.py
@@ -1,10 +1,10 @@
"""
convert_xls_to_ods.py
convert_xls_to_xlsx.py
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
This shows how to use **Book** to convert
xls file to ods file.
This shows how to use **save_book_as** to convert
xls file to xlsx file.
What this example implies is that you can do the conversion in
between these formats:
Expand All @@ -19,19 +19,18 @@
xlsm y y y y y y
---- --- --- --- --- ---- ----
you will need to install pyexcel-ods or pyexcel-ods3
you will need to install pyexcel-xls and pyexcel-xlsx
depending on your python version
pip install pyexcel-xls
pip install pyexcel-ods3
pip install pyexcel-xlsx
"""
import os
import pyexcel as pe


def main(base_dir):
# Simple open the file using Book
pe.save_book_as(
file_name=os.path.join(base_dir, "multiple-sheets.xls"),
dest_file_name=os.path.join(base_dir, "multiple-sheets.xlsx")
Expand Down
7 changes: 5 additions & 2 deletions examples/basics/jsonify.py
Expand Up @@ -2,17 +2,20 @@
jsonify.py
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
You will need pyexcel-text for json output
"""
import os
import pyexcel as pe
import json


def main(base_dir):
# "example.xls","example.xlsx","example.ods", "example.xlsm"
sheet = pe.get_sheet(file_name=os.path.join(base_dir,
"example.csv"))
print(json.dumps(sheet.to_array()))
print(sheet.json)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/read_cell_by_cell.py
Expand Up @@ -3,7 +3,7 @@
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
This shows how to use **Reader** class to go through a single
This shows how to use get_sheet() to go through a single
page spreadsheet, The output is::
1.0
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/read_column_by_column.py
Expand Up @@ -3,7 +3,7 @@
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
This shows a pythonic way to use **Reader** class to go through a single
This shows a pythonic way to use get_sheet to go through a single
page spreadsheet column by column. The output is::
[1.0, 4.0, 7.0]
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/series.py
Expand Up @@ -5,7 +5,7 @@
This shows how to use `name_columns_by_row` to get the data in various ways.
you will need to do `pip install pyexcel-ods3`
you will need to do `pip install pyexcel-xls`
"""
# please install pyexcel-ods
Expand Down
39 changes: 23 additions & 16 deletions examples/basics/write_excel_book.py
Expand Up @@ -3,26 +3,33 @@
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
This shows how to use **Book** class to write a dictionary
This shows how to use save_book_as to write a dictionary
to sheet spreadsheet.
Please install pyexcel-xls.
"""
import os
import pyexcel as pe

# the dictionary should look like the following:
# * key: a string typed key
# * value: a two dimensional array or a list of lists
data = {
"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]]
}
# In order to keep the order of the sheets, please use OrderedDict

# Now simply choose the filename and format you want to save
# file format is decided by the file extension
pe.save_book_as(bookdict=data, dest_file_name="multiple-sheets.xls")

# The output of the file is "multiple-sheets.xls"

def main(base_dir):
# the dictionary should look like the following:
# * key: a string typed key
# * value: a two dimensional array or a list of lists
data = {
"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]]
}
# In order to keep the order of the sheets, please use OrderedDict

# Now simply choose the filename and format you want to save
# file format is decided by the file extension
pe.save_book_as(bookdict=data, dest_file_name="multiple-sheets.xls")

# The output of the file is "multiple-sheets.xls"


if __name__ == '__main__':
main(os.getcwd())
4 changes: 2 additions & 2 deletions examples/cookbook/merge_sheets.py
Expand Up @@ -16,8 +16,8 @@
def main(base_dir):
merged = pe.Book()
files = glob.glob(os.path.join(base_dir, "scattered-csv-files", "*.csv"))
for file in files:
merged += pe.load(file)
for csv_file in files:
merged += pe.load(csv_file)
merged.save_as("merged.xls")


Expand Down
@@ -1,5 +1,5 @@
"""
imort_xls_into_database_via_sqlalchemy.py
import_xls_into_database_via_sqlalchemy.py
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
Expand Down
2 changes: 1 addition & 1 deletion examples/formatting/formatter01.py
@@ -1,5 +1,5 @@
"""
pyexcel_server.py
formater01.py
:copyright: (c) 2014-2017 by Onni Software Ltd.
:license: New BSD License, see LICENSE for more details
Expand Down
2 changes: 1 addition & 1 deletion examples/formatting/formatter02.py
Expand Up @@ -5,7 +5,7 @@
This example shows you how to use custom formatter function
Please install pyexcel-ods3
Please install pyexcel-xls
"""
import os
import pyexcel as pe
Expand Down
2 changes: 1 addition & 1 deletion pyexcel/sheets/sheet.py
@@ -1,6 +1,6 @@
"""
pyexcel.sheets.sheet
~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
Building on top of matrix, adding named columns and rows support
Expand Down

0 comments on commit 689f21c

Please sign in to comment.