Julian Gonzalez

Generation

generate functionFri, 31 Mar 2023

Read excel file in .NEt 6 using OfficeOpenXml

using System; using System.Diagnostics; using System.IO; using OfficeOpenXml; public class Program { public static void Main() { FileInfo file = new FileInfo("data.xlsx"); ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using (ExcelPackage package = new ExcelPackage(file)) { ExcelWorksheet worksheet = package.Workbook.Worksheets[0]; string name = worksheet.Cells[2, 1].Value.ToString(); string email = worksheet.Cells[2, 2].Value.ToString(); string phone = worksheet.Cells[2, 3].Value.ToString(); string state = worksheet.Cells[2, 4].Value.ToString(); int age = int.Parse(worksheet.Cells[2, 5].Value.ToString()); Debug.WriteLine($"Name: {name}, email: {email}"); } } }

Questions about programming?Chat with your personal AI assistant