我正在尝试在Excel导出中删除DateTimeOffset字段的时间部分,但我无法使其正常工作。
这是我要显示的字段:
[DataType(DataType.DateTime)]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTime ProjectStartDate { get; set; }
这是我要映射的字段:
public DateTimeOffset ProjectStartDate { get; set; }
这是我做映射的地方:
ProjectStartDate = p.ProjectStartDate,
我正在使用EPPlus生成导出,如下所示:
ExcelWorksheet wsExpenses = pck.Workbook.Worksheets.Add("Expenses");
wsExpenses.Cells["A1"].LoadFromCollection(expenses, true);
wsExpenses.Column(5).Style.Numberformat.Format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern;
答案 0 :(得分:0)
找出来,必须将其在映射中拉开:
before_create :rollback_if_similar_exists
after_rollback :update_existing_record
def rollback_if_similar_exists
throw :abort if Product.exists? name: self.name
end
def update_existing_record
# do here what you need
puts name
puts "find the existing record"
puts "update data"
end