openpyxl模块-----------------------删除完全Excel空行
删除空行代码:
import openpyxl
index_row = []
wb = openpyxl.load_workbook('table.xlsx')
ws = wb['Sheet1']
# loop each row in column A
for i in range(1, ws.max_row):
# define emptiness of cell
if ws.cell(i, 1).value is None:
# collect indexes of rows
index_row.append(i)
# loop each index value
for row_del in range(len(index_row)):
ws.delete_rows(idx=index_row[row_del], amount=1)
# exclude offset of rows through each iteration
index_row = list(map(lambda k: k - 1, index_row))
wb.save('13.xlsx')
实现效果如下:
删除之后: