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

问题描述 投票:0回答:1

我正在尝试将.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(fileName, oMissing, oMissing,
                                    oMissing, oMissing, oMissing, oMissing, 
    oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, 
    oMissing);
    wb.Application.DisplayAlerts = false;
    wb.SaveAs(svfileName, 
    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 = "" });
c# excel iis model-view-controller converters
1个回答
0
投票

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

Microsoft.Office.Interop.Excel.dll只是一个转换器(称为Interop程序集),可以帮助您与Excel对话。

您可以尝试使用ClosedXML来满足您的要求。

© www.soinside.com 2019 - 2024. All rights reserved.