电子表格GUI-Python 3.4

电子表格GUI-Python 3.4,python,excel,user-interface,tkinter,spreadsheet,Python,Excel,User Interface,Tkinter,Spreadsheet,我希望用户从Excel复制数据并将其粘贴到类似于GUI的电子表格中,然后按OK。这些数据(三列+100/1000行)将存储在一个数组中,以便在程序中进一步进行后续计算 我更喜欢使用tkinter,因为它已经包含在我的Python安装中,而Python3.4不支持wxPython等 我已经有了以下内容,但存在一些问题: 1.我无法将数据粘贴到表中。 2.行数是固定的。那么,如果我的数据大于表格,该怎么办 除非您想花几个月的时间编写自己的代码,将excel工作表“翻译”成python可以使用的东西

我希望用户从Excel复制数据并将其粘贴到类似于GUI的电子表格中,然后按OK。这些数据(三列+100/1000行)将存储在一个数组中,以便在程序中进一步进行后续计算

我更喜欢使用tkinter,因为它已经包含在我的Python安装中,而Python3.4不支持wxPython等

我已经有了以下内容,但存在一些问题: 1.我无法将数据粘贴到表中。 2.行数是固定的。那么,如果我的数据大于表格,该怎么办


除非您想花几个月的时间编写自己的代码,将excel工作表“翻译”成python可以使用的东西,否则我建议您看看:


根据文件(.xls、.xlsx)的类型,您需要使用特定的模块进行读/写。更多信息可在图书馆文档中找到

这里有一个简单的程序,可以打印到屏幕上的.xls文件,这应该可以帮助您开始

import xlrd
from tkFileDialog import askopenfile

data = tkFileDialog.askopenfilename()

book = xlrd.open_workbook(data) #open our xls file
sheet = book.sheets()[0] #book.sheets() returns a list of objects alternatively...
sheet = book.sheet_by_name("qqqq") #we can pull by name
sheet = book.sheet_by_index(0) #or by the index it has in excel's sheet collection

r = sheet.row(0) #returns all the CELLS of row 0,
c = sheet.col_values(0) #returns all the VALUES of row 0,

datastore = [] #make a data store

for i in xrange(sheet.nrows):
    datastore.append(sheet.row_values(i)) #drop all the values in the rows into datastore
print (datastore)

取自

stackoverflow的代码示例不是代码编写服务。请尝试自己解决问题,然后返回stackoverflow并提出具体问题。我得到“名称‘tkFileDialog’未定义”抱歉,我忘记您需要导入tkFileDialog,而不是tkinter。该程序应该在Python2.7上运行,Python3.0对tkinter程序使用不同的语法,但基本思想是相同的。
import xlrd
from tkFileDialog import askopenfile

data = tkFileDialog.askopenfilename()

book = xlrd.open_workbook(data) #open our xls file
sheet = book.sheets()[0] #book.sheets() returns a list of objects alternatively...
sheet = book.sheet_by_name("qqqq") #we can pull by name
sheet = book.sheet_by_index(0) #or by the index it has in excel's sheet collection

r = sheet.row(0) #returns all the CELLS of row 0,
c = sheet.col_values(0) #returns all the VALUES of row 0,

datastore = [] #make a data store

for i in xrange(sheet.nrows):
    datastore.append(sheet.row_values(i)) #drop all the values in the rows into datastore
print (datastore)