如何将Excel文件作为数组读入Python?

时间:2016-04-29 16:25:14

标签: python excel

我正在尝试将Excel文件转换为Python中的数组。

我的代码如下所示:

from openpyxl import Workbook
import xlrd

wb = Workbook()
ws = wb.active
book = xlrd.open_workbook('example.xlsx')
sheet = book.sheet_by_name("examplesheet")
data = [[sheet.cell_value(r,c) for c in range(sheet.ncols)] for r in range(sheet.nrows)]
print data

我收到错误代码此目录不存在

但我确信它确实存在。另外,奇怪的是我可以打开我之前用Python创建的excel文件。

0 个答案:

没有答案