Parse excel(xlsx/xls/csv) to other format(csv, json).
Project description
xlparser
Parse excel(xlsx/xls/csv) to other format(csv, json).
Warning: some old versions of xls are not supported.
Install
pip install xlparser
pip3 install xlparser
Usage
$ xlparser -h
Usage:
# Convert xlsx to csv
$ xlparser.py source.xlsx [options] > new.csv
# Convert csv to csv
$ xlparser.py source.csv [options] > new.csv
# Convert csv to json
$ xlparser.py source.csv [options] > new.json
options:
-h For help.
-csv Export to csv(by default).
-json Export to json.
CLI Usage
Convert xlsx to csv
$ xlparser src.xlsx | tee test.csv
foo, bar
看,我,变
Convert csv to json
$ xlparser test.csv -json | tee test.json
[["foo", "bar"], ["看", "我", "变"]]
Module Usage
Parse any type of file
The parse
function supports the following file format:
def parse(src):
if src.endswith('.xls'):
return parseXls(src)
if src.endswith('.xlsx'):
return parseXlsx(src)
if src.endswith('.csv'):
return parseCsv(src)
parse
any type of file to rows:
>>> from xlparser import parse, saveCsv
>>> rows = parse('some.xlsx')
>>> list(rows)
[['foo', 'bar'], ['看', '我', '变']]
Save rows to csv
>>> saveCsv(rows, 'test.csv')
Csv operation
>>> from xlparser import *
>>> rows = [('foo','bar'), ('看','我','变')]
>>> saveCsv(rows, 'test.csv')
>>> list(parseCsv('test.csv'))
[['foo', 'bar'], ['看', '我', '变']]
Zip operation
>>> from xlparser import loadZip
>>> zf = loadZip('test.xlsx')
>>> print(zf.filelist)
......
>>> zf.extract('xl/media/image1.png', '/tmp')
>>> os.rename('/tmp/'+'xl/media/image1.png', './image1.png')
Required
- python>=3.5
- xlrd: required by xls
- openpyxl>=2.5.4: required by xlsx
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xlparser-0.2.15.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for xlparser-0.2.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3340ec1f76547134a1c26414c2544fd714df3684c3249fb02ae0040387d1188 |
|
MD5 | 56d1b4aa801b4b0322dccb26f1321a14 |
|
BLAKE2b-256 | cf9295bde84342c04e24ab24114c9ced8d622a37f2c03081d99ca915ce2602e8 |