I am facing incorrect max_row result though there is no cell value. When cell format is in normal or general format, Max_row is giving me correct result based on cell containing data.
But when in an empty sheet cell format is changed to “date/custom” with no data containing, it counts them as containing data in those cells and provide me wrong maximum row number.
In Below case, i fetched data from master.xlsx file and write it into Gold.xlsx file. While the input (Gold.xlsx) file is general format, data have fetched correctly with correct max_row value.
but 2nd time, then i convert 1st two cells into “date” format with no values. But it counted the maxrow from 3rd row, showing incorrect result.
It works Fine and got accurate result when all cell format is in “General”
Incorrect input after 1st two cell is in “Date” format inspite of no value exist
[
import openpyxl
import os
wb_main = openpyxl.load_workbook("C:\Users\wasif.hossain\Desktop\File\1\Master.xlsx")
wb_main2 = openpyxl.load_workbook("C:\Users\wasif.hossain\Desktop\File\1\Gold.xlsx")
ws_main = wb_main["Sheet1"]
ws_main2 = wb_main2["Sheet1"]
x = ws_main.iter_rows(min_row=1, max_row=2, min_col=1, max_col=1)
for n in x:
for y in n:
revenue = y.value
ws_main2.cell(column=1, row=sheet.max_row+1).value = revenue
wb.save(file)
]
wam007 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.