easyexcel 读取excel 跳过空行
要实现在读取 Excel 文件时跳过空行,可以使用以下代码示例:
import easyexcel as excel
def read_excel(file_path):
workbook = excel.open_workbook(file_path)
sheet = workbook.get_sheet_by_index(0) # 获取第一个工作表
rows = sheet.rows
for row in rows:
if row: # 判断行是否为空
values = [cell.value for cell in row]
print(values)
# 调用函数读取 Excel 文件
read_excel("example.xlsx")
在上面的代码中,我们使用 easyexcel 库打开 Excel 文件并获取第一个工作表。然后,我们遍历工作表的每一行,并使用条件判断跳过空行。如果行不为空,我们将获取每个单元格的值并打印出来。
请确保已安装 easyexcel 库,并将 example.xlsx 替换为你要读取的 Excel 文件的路径
原文地址: https://www.cveoy.top/t/topic/iJ70 著作权归作者所有。请勿转载和采集!