使用" FILEPICKER"打开数据文件(csv,xls,xlsx,ods等)。蟒蛇?

时间:2016-09-25 01:29:15

标签: excel csv pyqt xls filepicker

当我们知道文件的名称和类型时,我知道如何打开数据文件,但是我们如何使用文件选择器来选择文件?

import pyexcel as pe  
records = pe.get_records(file_name="your_file.xls")  
for record in records:  
     print("%s is aged at %d" % (record['Name'], record['Age']))

2 个答案:

答案 0 :(得分:1)

您可以定义函数以返回可用作pe.get_records()输入的函数名称。      from tkinter import * root = Tk() def get_file_name(): global root root.filename = filedialog.askopenfilename(initialdir = "D:/",title = "choose your excel file",filetypes = (("excel files","*.xls"),("all files","*.*"))) print (root.filename) root.withdraw() return root.filename

答案 1 :(得分:1)

我遇到了问题,现在这个代码运行了!

filters = (
            'Data Files (*.csv *.txt *.xls *.xml *.xlsx *.xlsm)',
        )
        path, filter = QtGui.QFileDialog.getOpenFileNameAndFilter(
            self, 'Open File', '', ';;'.join(filters))