I did some tests and it worked with ClosedXML NuGet Package :
using var workbook = new XLWorkbook();
var ws = workbook.Worksheets.Add("Sheet1");
ws.Cell("A1").Value = "Hello world!";
using var ms = new MemoryStream();
workbook.SaveAs(ms);
ms.Position = 0;
then with System.Net.Mail.MailMessage for mail :
var attachment = new Attachment(ms, "Test.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
mail.Attachments.Add(attachment);
then with SmtpClient.Send, I received the mail with Test.xlsx attached and correct format