我读的是xlsx文件,像这样,
import openpyxl
book = openpyxl.load_workbook('test.xlsx')
sheet = book.get_sheet_by_name(sheets['DATA'])
allCells = sheet.get_cell_collection()
print allCellsallCells是一个无序的openpyxl.cell.Cell对象列表。allCells看起来像,
[<Cell Data.B4>, <Cell Data.A6>, <Cell Data.B6>, <Cell Data.A1>, <Cell Data.B5>, <Cell Data.A3>, <Cell Data.A2>, <Cell Data.A5>, <Cell Data.B1>, <Cell Data.B2>]我希望将此列表按列排序,然后按行索引排序。对怎么做有什么想法吗?
发布于 2013-09-04 20:35:41
可以获取列表中每个单元格的行和列信息,如下所示:
import openpyxl
wb = openpyxl.workbook.Workbook()
ws = wb.worksheets[0]
a=ws.cell('D6')
a.row
6
a.column
'D'现在,这只是一个问题,根据你想要的任何标准来分类。下面是用于排序的不同算法的列表。这个帖子描述了如何根据对象的属性对列表进行排序。有什么问题吗?我会相应地编辑答案。
https://stackoverflow.com/questions/18623141
复制相似问题