The maximum number of rows for a modern Excel file is around 1 million per sheet. You can't have more than that.
I wouldn't even try exporting 20M records as an Excel file — it's just not the right format for it. I'd export it as CSV.
You should also show your code. You didn't even mention which library you're using.
You can't easily "append" data to an Excel file. An Excel file is just a bunch of XML files in a zip archive, and you have to parse the entire sheet before you can write anything to it. If you keep restarting this process or don't use any kind of chunked writing, then it's going to be very slow with that many records.