// Creating a new Excel workbook using (var excelPackage = new ExcelPackage()) { // Adding a new worksheet to the workbook ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Sheet1"); // Adding data to the first row and first column of the worksheet worksheet.Cells[1, 1].Value = "Hello World!"; // Saving the workbook to a file File.WriteAllBytes(@"C:\temp\MyWorkbook.xlsx", excelPackage.GetAsByteArray()); }
// Loading an existing Excel workbook using (var excelPackage = new ExcelPackage(new FileInfo(@"C:\temp\MyWorkbook.xlsx"))) { // Getting the first worksheet of the workbook ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets[1]; // Reading the value of the first cell of the worksheet var firstCellValue = worksheet.Cells[1, 1].Value; // Displaying the value of the first cell Console.WriteLine(firstCellValue); }In this example, we load an existing Excel workbook from a file using the `ExcelPackage` class. We then get the first worksheet of the workbook using the `Item` property of the `ExcelWorksheets` collection. We read the value of the first cell of the worksheet and display it on the console. Package library: OfficeOpenXml (version 4.5.3)