Julian Gonzalez

Generation

generate functionFri, 31 Mar 2023

Read excel file in .NEt 6 using EPPlus library

public static void Main(string[] args) { //nuget package manager or dotnet cli //install-package EPPlus //https://www.nuget.org/packages/EPPlus/ //https://github.com/JanKallman/EPPlus FileInfo file = new FileInfo(@"C:\Test\" + "ExcelSample.xlsx"); ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using (ExcelPackage package = new ExcelPackage(file)) { //Get the work book in the file ExcelWorkbook workBook = package.Workbook; if (workBook != null) { if (workBook.Worksheets.Count > 0) { //Get the first worksheet ExcelWorksheet currentWorksheet = workBook.Worksheets.First(); //Read some data Console.WriteLine(currentWorksheet.Cells["B1"].Value); Console.WriteLine(currentWorksheet.Cells["B2"].Value

Questions about programming?Chat with your personal AI assistant