簡體   English   中英

將 .xlsx 文件轉換為 .xls(97-2003) 工作簿 C#

[英]convert .xlsx file to .xls(97-2003) workbook 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 只是一個翻譯器(稱為互操作程序集),可幫助您與 Excel 對話。

您可以嘗試使用ClosedXML來實現您的要求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM