As the document from https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3, the excel sheet is limited by 1,048,576 rows and 16,384 columns.
For my cases, I define the maximum of lines in each sheet is 1 000 000 row, my columns is lower than the maximum of column number, so I don't care about that. And If it's over than maximum of rows, I will write to the next sheet.