Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Epplus - Cannot change cell value or cell header

Tags:

epplus

I have a problem when change the value of a cell. Here is my code:

FileInfo newFile = new FileInfo(file); ExcelPackage pck = new ExcelPackage(newFile);

        var wsData = pck.Workbook.Worksheets.Add("Absent Employee List");
        var dataRange = wsData.Cells["A1"].LoadFromCollection(
                from s in emps
                orderby s.EmployeeCode
                select s,
                true, OfficeOpenXml.Table.TableStyles.Medium2
                );
        wsData.Cells[2, 4, dataRange.End.Row, 4].Style.Numberformat.Format = "dd-mm-yyyy"
        wsData.Cells[2, 5, dataRange.End.Row, 5].Style.Numberformat.Format = "dd-mm-yyyy";

        wsData.Cells["A1"].Value = "Employee Code"; // [1, 1]
        wsData.Cells["B1"].Value = "Full Name"; // [1, 2]
        wsData.Cells["C1"].Value = "Department"; // [1, 3]

        dataRange.AutoFitColumns();

        pck.SaveAs(newFile);

When I open the file after creating, the header of A1, B1, C1 didn't change. Did i miss something? thank you for your help.

like image 881
Jacky Tran Avatar asked Feb 17 '26 05:02

Jacky Tran


1 Answers

Try this

wsData.Cells[1,1].Value = "Employee Code";
wsData.Cells[2,1].Value = "Full Name";
wsData.Cells[3,1].Value = "Department"; 

This is what worked for me!

like image 104
gib Avatar answered Feb 21 '26 14:02

gib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!