Hi. I'm working with Visual Studio 2022 and I have an application that uses excel. I'd like to know your opinion on the interfaces available: Interop, ClosedXML or any other. Which one is the best?
Thank you.
Loading
Hi. I'm working with Visual Studio 2022 and I have an application that uses excel. I'd like to know your opinion on the interfaces available: Interop, ClosedXML or any other. Which one is the best?
Thank you.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mayooran NavamanyRank #438 · 5.7K reputationPosted Oct 10, 2024, 9:30 PM EDT
For working with Excel in .NET applications, there are several libraries you can choose from, each with its strengths. Here's a comparison of some of the most popular ones:
1. Interop (Microsoft.Office.Interop.Excel)Best For: Desktop applications where you need complete Excel functionality and the environment is guaranteed to have Excel installed.
2. ClosedXMLBest For: Applications that need to generate or read simple to moderately complex Excel files without requiring Excel to be installed. Great for server-based applications like web apps.
3. EPPlusBest For: Applications that need more advanced Excel features but want the performance of a non-Interop solution.
Vishal YelveRank #178 · 13.6K reputationPosted Oct 11, 2024, 3:11 AM EDT
Hi Ismael,
Do refer my article
https://www.c-sharpcorner.com/article/how-to-read-data-from-an-excel-sheet/
Tahir AnsariRank #366 · 6.8K reputationPosted Oct 11, 2024, 12:06 AM EDT
Refer this article
https://www.c-sharpcorner.com/article/creating-excel-reports-with-epplus-in-asp-net-core-8-0/
Tuhin PaulRank #7 · 71.9K reputationPosted Oct 12, 2024, 2:24 PM EDT
using OfficeOpenXml; class EPPlusExample { public void CreateExcelFile() { // Create a new Excel package using (ExcelPackage package = new ExcelPackage()) { // Add a new workbook ExcelWorkbook workbook = package.Workbook; // Get the first sheet ExcelWorksheet worksheet = workbook.Worksheets.Add("Sheet1"); // Write data to cells worksheet.Cells[1, 1].Value = "Hello"; worksheet.Cells[1, 2].Value = "World"; // Save the package package.SaveAs(new FileInfo("example.xlsx")); } } }ExcelPackageclass represents an Excel file. This creates a new instance of an Excel package, which will be the Excel file in memory.usingstatement ensures that the resources used by theExcelPackagewill be automatically disposed of once the operation is complete.Workbookproperty of theExcelPackageobject gets the workbook associated with the Excel file. A workbook can have multiple sheets.Cellsproperty is used to access specific cells by their row and column indices. The cell at position[1, 1](i.e., A1) is assigned the value "Hello", and[1, 2](i.e., B1) is assigned the value "World".SaveAsmethod saves the Excel package to a file. Here, the file is saved as "example.xlsx" in the current directory. TheFileInfoclass is used to specify the file location and name.Leon DRank #851 · 2.6K reputationPosted Oct 13, 2024, 10:37 PM EDT
You can also check Spire.XLS, it has a free version named Free Spire.XLS:
https://www.nuget.org/packages/Spire.XLS
https://www.nuget.org/packages/FreeSpire.XLS
This library supports various excel formats, including .xls, .xlsx, .xlsm, .xlsb, and more. Additionally, it operates independently, so there’s no need to have MS Office or any other software installed. Here is the library's official documentation for your reference:
https://www.e-iceblue.com/Tutorials/Spire.XLS/Spire.XLS-Program-Guide/Spire.XLS-Program-Guide-Content.html