现在我可以阅读EXCEL文件的所有表格了。
e.msgbox("select Excel File")
updated_deleted_xls = e.fileopenbox()
book = xlrd.open_workbook(updated_deleted_xls, formatting_info=True)
openfile = e.fileopenbox()
for sheet in book.sheets():
for row in range(sheet.nrows):
for col in range(sheet.ncols):
thecell = sheet.cell(row, 0)
xfx = sheet.cell_xf_index(row, 0)
xf = book.xf_list[xfx]
最佳答案
如果您从桌面或命令行打开编辑器,则必须在尝试读取文件时指定文件路径:
import pandas as pd
df = pd.read_excel(r'File path', sheet_name='Sheet name')
或者,如果您在文件目录中打开编辑器,则可以直接使用 panda 库进行阅读
import pandas as pd
df = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='Title Sheet')
df1 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx',sheet_name='Transactions')
df2 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='NewCustomerList')
df3 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='CustomerDemographic')
df4 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='CustomerAddress')
关于python - 如何在 Python 中从 My XLS 文件中读取特定工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48663698/