我正在尝试将.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 = "" });
答案 0 :(得分:0)
据我所知,您无法在未安装Excel的服务器上使用Microsoft.Office.Interop.Excel
。
Microsoft.Office.Interop.Excel.dll只是一个翻译器(称为Interop程序集),可以帮助您与Excel对话。
您可以尝试使用ClosedXML来满足您的要求。