OpenXML - Writing a date into Excel spreadsheet results in unreadable content

前端 未结 7 826
离开以前
离开以前 2020-12-10 11:21

I am using the following code to add a DateTime to a column in my spreadsheet:

var dt = DateTime.Now;
r.AppendChild(new Cell()
    {         


        
7条回答
  •  佛祖请我去吃肉
    2020-12-10 12:07

    private Cell CreateCellWithValue(DateTime columnValue, uint? styleIndex, string cellReference)
    {
        Cell c = new Cell();
        c.DataType = CellValues.Number;
        c.CellValue = new CellValue(columnValue.ToOADate().ToString(new CultureInfo("en-US")));
        c.CellReference = cellReference;
        c.StyleIndex = styleIndex;
    
        return c;
    }
    

提交回复
热议问题