3

更改单元格的值时出现问题。这是我的代码:

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);

创建后打开文件时,A1,B1,C1的标题没有改变。我错过了什么?感谢您的帮助。

4

2 回答 2

1

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!

于 2014-03-26T12:36:24.867 回答
0

这是库中的一个错误,已在之前的版本中修复。您可以在此处找到错误描述以及解决方法:

https://epplus.codeplex.com/workitem/15245

ExcelTable excelTable = this.worksheet.Tables[0];
excelTable.Columns[1].Name = "Test";
于 2015-06-26T06:51:54.660 回答