2012-08-05 137 views

回答

0

我用xlrd读写.xls文件的例子herehere

+0

哪一个是最好的? – Antoni4040 2012-08-05 15:23:23

+0

我不知道哪一个是最好的,但对于我的项目xlrd一直很有希望 – Rakesh 2012-08-05 15:25:18

0

导入和读取.xls文件,我将与xlutils开始,特别是xlrd

+0

任何代码的例子吗? – Antoni4040 2012-08-05 15:14:16

1

试试我的图书馆pyexcel

假设您有一个csv,xls,xlsx文件,如下所示:

1,2,3 
4,5,6 
7,8,9 

下面的代码会给你的数据在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()) 

输出:

[[1, 2, 3], [4, 5, 6], [7, 8, 9]] 

您可以轻松地初始化QTableWidiget(sheet.number_of_rows(), sheet.number_of_columns()),然后用数组,data表格部件填补。

更多代码示例可以在这个页面中找到:https://github.com/chfw/pyexcel

API文档可以在这里找到:http://pyexcel.readthedocs.org/en/latest/api.html

+0

嘿伙计,有点晚了,但不错的答案无论如何... :) – Antoni4040 2014-09-19 11:34:21