尝试使用EPPlus读取.xls文件时出错

以下代码对于.xlsx工作正常,但对于.xls不起作用。 我得到了这个错误信息

无法打开包装。 包是一个OLE复合文档。 如果这是一个encryption的包,请提供密码

string filepath = txtBrowse.Text; FileStream stream = System.IO.File.Open(filepath, FileMode.Open, FileAccess.ReadWrite); //1. Reading from a binary Excel file ('97-2003 format; *.xls) IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); FileInfo newFile = new FileInfo(filepath); using (ExcelPackage package = new ExcelPackage(newFile)) { string sheetName = System.DateTime.Now.ToShortDateString(); foreach (OfficeOpenXml.ExcelWorksheet sheet in package.Workbook.Worksheets) { // Check the name of the current sheet if (sheet.Name == sheetName) { package.Workbook.Worksheets.Delete(sheetName); break; // Exit the loop now } } ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(System.DateTime.Now.ToShortDateString()); } 

我如何正确地做到这一点?

EPPlus不能使用XLS格式。 只有XLSX。 你需要find一个新的图书馆。

我成功地使用了托尼的答案https://stackoverflow.com/a/18904633/306515 ,只需使用Microsoft.Office.Interop.Excel转换它,然后仍然可以使用epplus