Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahuigo/xlparser
Parse file(xlsx/xls/csv) to other format(dict, csv, json, ...).
https://github.com/ahuigo/xlparser
csv python3 xls xlsx
Last synced: 22 days ago
JSON representation
Parse file(xlsx/xls/csv) to other format(dict, csv, json, ...).
- Host: GitHub
- URL: https://github.com/ahuigo/xlparser
- Owner: ahuigo
- License: mit
- Created: 2018-07-19T08:02:35.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-24T12:40:15.000Z (5 months ago)
- Last Synced: 2024-08-05T17:40:09.151Z (4 months ago)
- Topics: csv, python3, xls, xlsx
- Language: Python
- Homepage:
- Size: 73.2 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-hacking-lists - ahuigo/xlparser - Parse file(xlsx/xls/csv) to other format(dict, csv, json, ...). (Python)
README
# xlparser
Parse excel(xlsx/xls/csv) to other format(csv, xlsx, json).[![](https://img.shields.io/pypi/pyversions/xlparser.svg?longCache=True)](https://pypi.org/pypi/xlparser/)
[![](https://img.shields.io/pypi/v/xlparser.svg?maxAge=36000)](https://pypi.org/pypi/xlparser/)- [xlparser](#xlparser)
- [Install](#install)
- [Usage](#usage)
- [CLI Usage](#cli-usage)
- [Module Usage](#module-usage)
- [Parse any type of file](#parse-any-type-of-file)
- [Save to any type of file](#save-to-any-type-of-file)
- [Csv operation](#csv-operation)
- [Zip operation](#zip-operation)
- [Required](#required)[中文](README.zh.md)
## Install
pip install xlparser
# or
pip3 install xlparserIf you want to filter fields, it will be convenient with [xcut](https://github.com/ahuigo/xcut).
pip install xcut
# or
pip3 install xcut## Usage
$ xlparser -h
xlparser [options] INFILE [OUTFILE]\n
options:\n
-h For help.\n### CLI Usage
From xlsx to csv.$ xlparser source.xlsx new.csv
From csv to xlsx.
$ xlparser source.csv new.xlsx
From csv to json.
$ xlparser source.csv new.json
From xlsx to csv(stdout).
$ xlparser source.xlsx | head
$ xlparser src.xlsx | tee test.csv
name, score
"李雷,韩梅",15
小花,16Use xcut to filter fields.
$ xlparser src.xlsx | xcut --from-csv -f name
name
"李雷,韩梅"
小花$ xlparser src.xlsx | xcut --from-csv -f score,name
score,name
15,"李雷,韩梅"
16,小花Convert xlsx to csv
$ xlparser src.xlsx test.csv;
$ cat test.csv
name, age
李雷,15
小花,16Convert csv to json
$ xlparser test.csv test.json
[["name", "age"], ["李雷", "15"], ["小花", "16"]]### Module Usage
#### Parse any type of file
`parse` any type of file to rows:>>> from xlparser import parse, saveCsv
>>> rows = parse('some.xlsx')
>>> list(rows)
[['foo', 'bar'], ['看', '我', '变']]The `parse` function supports the following file formats: .csv, .xls, .xlsx .
#### Save to any type of file
Save rows to csv>>> from xlparser import saveCsv
>>> rows = [['foo', 'bar'], ['看', '我', '变']]
>>> saveCsv(rows, 'test.csv')Save rows to xlsx
>>> saveXlsx(rows, 'test.xlsx')
#### 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
1. python>=3.5
2. xlrd: required by xls
2. openpyxl>=2.5.4: required by xlsx