-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExcelManager.cs
31 lines (24 loc) · 1013 Bytes
/
ExcelManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using OfficeOpenXml;
using System;
using System.IO;
public class ExcelManager
{
public static void AddJobApplication(string jobTitle, string company, string comments)
{
string dateSubmitted = DateTime.Now.ToString("dddd d MMMM, yyyy");
// Open the Excel file for writing
using (var package = new ExcelPackage(new FileInfo("C:/Users/mjl82/Desktop/Jobs.xlsx")))
{
var worksheet = package.Workbook.Worksheets["JobApplications"];
// Find the next available row (assuming no empty rows in the middle)
int nextRow = worksheet.Dimension?.Rows ?? 1;
// Add data to the next row
worksheet.Cells[nextRow + 1, 1].Value = company;
worksheet.Cells[nextRow + 1, 2].Value = jobTitle;
worksheet.Cells[nextRow + 1, 3].Value = comments;
worksheet.Cells[nextRow + 1, 4].Value = dateSubmitted;
// Save the changes to the Excel file
package.Save();
}
}
}