[英]EPPlus cells not updated after number format
Im trying to change number format with epplus in excel to this format ([h]:mm:ss), and it seems to change the cells format correctly.我正在尝试使用 epplus 将 excel 中的数字格式更改为这种格式 ([h]:mm:ss),它似乎正确地更改了单元格格式。 But the cells value doesnt update after the format...
但是格式后单元格值不会更新...
As the picture shows the correct way of the text should be like the first cell on the picture.如图所示,正确的文本方式应该是图片上的第一个单元格。 It works if I click on the cells and presses enter again Picture
如果我单击单元格并再次按回车键,它就会工作Picture
var sheet = package.Workbook.Worksheets.Add(filename);
var tableRange = sheet.Cells["A1"].LoadFromCollection(list);
var table = sheet.Tables.GetFromRange(tableRange);
package.Save();
NumberFormat数字格式
[EpplusTableColumn(Order = 2, NumberFormat = "[h]:mm:ss")]
public string timeWorked { get; set; }
In the end, I want to use the SUM function in excel to calculate the total timeworked, but it doesnt work when the cells doesnt change to the format I have sat for it最后,我想使用 excel 中的 SUM function 来计算总工作时间,但是当单元格没有更改为我为它准备的格式时它不起作用
Firstly, change type from string
to TimeSpan
首先,将类型从
string
更改为TimeSpan
public TimeSpan TimeWorked { get; set; } = new TimeSpan(2, 18, 19);
Secondly, set printHeader
to true
其次,将
printHeader
设置为true
var tableRange = sheet.Cells["A1"].LoadFromCollection(actors, true);
For some reason column when using EpplusTableColumn
attribute headers need to be included in excel otherwise cell formatting doesn't work.由于某种原因,使用
EpplusTableColumn
属性标题时的列需要包含在 excel 中,否则单元格格式将不起作用。 I'm not sure if it's a bug or am I missing something.我不确定这是错误还是我遗漏了什么。
Would love if someone can give me more explanation.如果有人能给我更多解释,我会很高兴。
If you really don't want headers to show there is a workaround.如果您真的不想显示标头,则有一种解决方法。 Before saving remove first row from excel.
在保存之前从 excel 中删除第一行。
sheet.DeleteRow(1);
package.Save();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.