gpt4 book ai didi

Epplus - 无法更改单元格值或单元格标题

转载 作者:行者123 更新时间:2023-12-02 06:42:55 26 4
gpt4 key购买 nike

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

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 的 header 没有改变。我错过了什么?感谢您的帮助。

最佳答案

试试这个

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

这对我有用!

关于Epplus - 无法更改单元格值或单元格标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17969059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com