import openpyxl
def is_cell_empty(filename, cell_reference):
workbook = openpyxl.load_workbook(filename)
sheet = workbook.active
# Get the cell object
cell = sheet[cell_reference]
# Check if the cell value is None or an empty string
if cell.value is None or cell.value == '':
return True
return False
if is_cell_empty(r'C:\Users\Administrator\Desktop\新建 Microsoft Excel 工作表 (2).xlsx', 'A2'):
print('A2 is 空')
else:
print('A2 is 非空')
如何判断单元格是否为空
于 2023-04-24 20:30:35 首次发布