2012-08-05 191 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