将.xlsx文件转换为.xls(97-2003) 工作簿 C#



我正在尝试将.xlsx文件转换为.xls(97-2003(工作簿。 其中可能有大约 1000 行 n 更多. 是否有任何我可以使用的免费 NuGet 包? 我试过使用Microsoft.Office.Interop.Excel,但它在IIS上不起作用。

string sourceFileName = appSettings.ImageDirectory + "Report.xlsx";
string DestFileName = appSettings.ImageDirectory + "Report.xls";
object oMissing = Type.Missing;
var app = new Microsoft.Office.Interop.Excel.Application();
var wb = app.Workbooks.Open(sourceFileName, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, 
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, 
oMissing);
wb.Application.DisplayAlerts = false;
wb.SaveAs(DestFileName , 
Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8, Type.Missing, 
Type.Missing, Type.Missing, Type.Missing, 
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, 
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
app.Quit();
string fullPath = appSettings.ReportFolderPath + "/Report.xls"; 
return Json(new { path = fullPath, errorMessage = "" });

据我所知,您无法在未安装 Excel 的服务器上使用Microsoft.Office.Interop.Excel

Microsoft.Office.Interop.Excel.dll只是一个翻译器(称为Interop程序集(,可帮助您与Excel交谈。

您可以尝试使用ClosedXML来实现您的要求。

最新更新