openpyxl 中的等效函数是什么?
What is the equivalent function in openpyxl?
在 xlrd 和 xlwt 中将 sheet 的行追加到数组中我可以这样做:
Stuff = []
column_count = sheet.ncols - 1
for i in range (0, column_count):
Stuff.append([sheet.cell_value(row, i) for row in range(sheet.nrows)])
如何在 openpyxl 中执行等效操作?
您可以遍历工作表的行:
stuff = [[cell.value for cell in row] for row in sheet]
或者,如果您想按列分组,请使用 .columns
:
stuff = [[cell.value for cell in column] for column in sheet.columns]
列 属性 不可用于只读工作表,因为数据存储在行中。
在 xlrd 和 xlwt 中将 sheet 的行追加到数组中我可以这样做:
Stuff = []
column_count = sheet.ncols - 1
for i in range (0, column_count):
Stuff.append([sheet.cell_value(row, i) for row in range(sheet.nrows)])
如何在 openpyxl 中执行等效操作?
您可以遍历工作表的行:
stuff = [[cell.value for cell in row] for row in sheet]
或者,如果您想按列分组,请使用 .columns
:
stuff = [[cell.value for cell in column] for column in sheet.columns]
列 属性 不可用于只读工作表,因为数据存储在行中。