This question has already been answered:
You need a .net library to generate Excel files and CSV. Yes, there are a lot of answers on the Internet in particular, excellent answers here
But at best they date back to 2010, and much could have changed. So, what library do you recommend for now? And the pitfalls that you have when generating Excel files.
UPD Need a free library. UPD2 Need a free library with a license compatible with proprietary software.