使用c#改变电子邮件中excel附件的版本

我正在尝试发送电子邮件附加Excel的xlsx文件。 我可以在我的笔记本电脑上下载附带的excel文件,而银河手机却无法在iphone上下载。 所以我想降低Excel版本使用https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.xlfileformat.aspx 。 为此,当我更改代码

wb.SaveAs("filename.xls", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8); 

它说SaveAs没有FileFormat参数。 他们说他们需要2个参数。 (streamstream,布尔validation)

所以我不知道在哪里可以把这些文件格式从我的代码更改从xlsx到xls的文件格式。

  //set DataTable Name of Excel Sheet data.TableName = "E_Data"; //Create a New Workbook using (XLWorkbook wb = new XLWorkbook()) { //Add the DataTable as Excel Workhseet wb.Worksheets.Add(data); using (MemoryStream memoryStream = new MemoryStream()) { //Save the Excel Workbook to MemoryStream wb.SaveAs(memoryStream); //Convert MemoryStream to Byte array byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); ... mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "NSOList.xlsx")); } } 

您正在使用ClosedXml ,ClosedXML不支持旧格式,因此您不能将文件保存为xls。 如果您可以使用Microsoft.Office.Interop.Excel命名空间(即办公室安装在server \ pc上),这将非常容易, 使用Interop.Excel创build您的Excel文件,并使用SaveAs()方法保存,例如: wb.SaveAs(c:\\memoryStream.xls,XlFileFormat.xlOpenXMLWorkbook)