Reputation: 2319
How can I import an .xls file using Python and PyQt and then populate a QTableWidget with it's contents?
Upvotes: 1
Views: 5165
Reputation: 4592
try my library pyexcel
,
Suppose you have a csv, xls, xlsx file as the following:
1,2,3
4,5,6
7,8,9
The following code will give you the data in json
from pyexcel as pe
import json
# "example.xls", please import pyexel.ext.xls
# "example.xlsx", please import pyexcel.ext.xlsx
# "example.ods", please import pyexcel.ext.ods or pyexcel.ext.ods3
sheet= pe.load("example.csv")
print json.dumps(sheet.to_array())
The output is:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
You can easily initialize QTableWidiget(sheet.number_of_rows(), sheet.number_of_columns())
and then fill in the table widget with the array, data
.
More code examples can be found in this page: https://github.com/chfw/pyexcel
API documentation can be found here: http://pyexcel.readthedocs.org/en/latest/api.html
Upvotes: 1
Reputation: 82785
I use xlrd for reading and writing .xls files examples here and here
Upvotes: 1
Reputation: 1342
For importing and reading the .xls file, I would start with xlutils, specifically xlrd
Upvotes: 0