agate-excel 0.4.1#
agate-excel adds read support for Excel files (xls and xlsx) to agate.
Important links:
agate https://agate.rtfd.org
Documentation: https://agate-excel.rtfd.org
Repository: https://github.com/wireservice/agate-excel
Install#
To install:
pip install agate-excel
For details on development or supported platforms see the agate documentation.
Usage#
agate-excel uses a monkey patching pattern to add read for xls and xlsx files support to all agate.Table
instances.
import agate
import agateexcel
Importing agate-excel adds methods to agate.Table
. Once you’ve imported it, you can create tables from both XLS and XLSX files.
table = agate.Table.from_xls('examples/test.xls')
print(table)
table = agate.Table.from_xlsx('examples/test.xlsx')
print(table)
table = agate.Table.from_xlsx('examples/test.xlsx', sheet=1)
print(table)
table = agate.Table.from_xlsx('examples/test.xlsx', sheet='dummy')
print(table)
table = agate.Table.from_xlsx('examples/test.xlsx', sheet=[1, 'dummy'])
print(table)
Both Table
methods accept a sheet
argument to specify which sheet to create the table from.
API#
- agateexcel.table_xls.from_xls(cls, path, sheet=None, skip_lines=0, header=True, encoding_override=None, row_limit=None, **kwargs)#
Parse an XLS file.
- Parameters:
path – Path to an XLS file to load or a file-like object for one.
sheet – The names or integer indices of the worksheets to load. If not specified then the first sheet will be used.
skip_lines – The number of rows to skip from the top of the sheet.
header – If
True
, the first row is assumed to contain column names.row_limit – Limit how many rows of data will be read.
- agateexcel.table_xlsx.from_xlsx(cls, path, sheet=None, skip_lines=0, header=True, read_only=True, reset_dimensions=None, row_limit=None, **kwargs)#
Parse an XLSX file.
- Parameters:
path – Path to an XLSX file to load or a file-like object for one.
sheet – The names or integer indices of the worksheets to load. If not specified then the “active” sheet will be used.
skip_lines – The number of rows to skip from the top of the sheet.
header – If
True
, the first row is assumed to contain column names.read_only – If
True
, the XLSX file is opened in read-only mode, to reduce memory consumption.reset_dimensions – If
True
, do not trust the dimensions in the file’s properties, and recalculate them based on the data in the file.row_limit – Limit how many rows of data will be read.
Changelog#
0.4.1 - November 20, 2023#
fix:
Table.from_xlsx()
no longer errors on unsized sheets.
0.4.0 - November 7, 2023#
The
reset_dimensions
argument toTable.from_xlsx()
defaults toNone
instead ofFalse
. Ifreset_dimensions
isNone
, and if the worksheet’s dimensions areA1:A1
, recalculate the worksheet’s dimensions. To disable this behavior, setreset_dimensions
toFalse
.
0.3.0 - October 30, 2023#
If the
reset_dimensions
argument toTable.from_xlsx()
is set, recalculate the worksheet’s dimensions, instead of assuming that the table’s width matches the first row’s.The
reset_dimensions
argument toTable.from_xlsx()
is ignored if theread_only
argument is false.Add Python 3.8, 3.9, 3.10, 3.11, 3.12 support.
Drop support for 3.5 (2020-09-13), 3.6 (2021-12-23), 3.7 (2023-06-27).
0.2.5 - August 8, 2021#
Add
six
toinstall_requires
.
0.2.4 - July 13, 2021#
Add
row_limit
keyword argument tofrom_xls
andfrom_xlsx
. (#40)Preserve column types from XLS files. (#36)
Add support for Compound File Binary File (CFBF) XLS files. (#44)
Close XLSX file before raising error for non-existent sheet. (#34)
Use less memory and close XLS files. (#39)
Drop support for Python 3.4 (end-of-life was March 18, 2019).
0.2.3 - March 16, 2019#
Fix bug in accepting
column_names
as keyword argument.Add a
reset_dimensions
argument toTable.from_xlsx()
to recalculate the data’s dimensions, instead of trusting those in the file’s properties.Include tests and examples in distribution.
agate-excel is now tested against Python 3.6 and 3.7.
Drop support for Python 3.3 (end-of-life was September 29, 2017).
Add support for openpyxl 2.6.0.
0.2.2 - January 28, 2018#
Add an
encoding_override
argument toTable.from_xls()
to override the encoding of the input XLS file.Add a
header
argument toTable.from_xls()
andTable.from_xlsx()
to indicate the presence of a header row.Add a
read_only
argument toTable.from_xlsx()
to allow disabling read-only mode for some spreadsheets.
0.2.1 - February 28, 2017#
Overload
Table.from_xls()
andTable.from_xlsx()
to accept and return multiple sheets.Add a
skip_lines
argument toTable.from_xls()
andTable.from_xlsx()
to skip rows from the top of the sheet.Fix bug in handling ambiguous dates in XLS. (#9)
Fix bug in handling an empty XLS.
Fix bug in handling non-string column names in XLSX.
0.2.0 - December 19, 2016#
Fix bug in handling of
None
in boolean columns for XLS. (#11)Removed usage of deprecated openpyxl method
get_sheet_by_name
.Remove monkeypatching.
Upgrade required agate version to
1.5.0
.Ensure columns with numbers for names (e.g. years) are parsed as strings.
0.1.0 - February 5, 2016#
Initial version.
License#
The MIT License
Copyright (c) 2017 Christopher Groskopf and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.