Epplus 设置Excel Cell Data

项目需要操作excel xlsm.200列左右数据,Aspose,操作指定文件异常.暂时没有想到好的思路,就使用原来用过的epplus,结果忘记如何设置数据类型了,就查了下,因为外网*麻烦,,做个标记:

[TestMethod]
public void Date_Format_Test()
{
    //http://*.com/questions/29473920/how-to-set-cell-data-type

    var existingFile = new FileInfo(@"c:\temp\temp.xlsx");
    if (existingFile.Exists)
        existingFile.Delete();

    using (var pck = new ExcelPackage(existingFile))
    {
        var ws = pck.Workbook.Worksheets.Add("Content");
        var date = DateTime.Now;

        //Raw date value as number
        ws.Cells["A1"].Value = date;

        //As "Short Date"
        ws.Cells["A2"].Value = date;
        ws.Cells["A2"].Style.Numberformat.Format = "mm-dd-yy";

        //As "Time"
        ws.Cells["A3"].Value = date;
        ws.Cells["A3"].Style.Numberformat.Format = "[$-F400]h:mm:ss\\ AM/PM";

        pck.Save();
    }
}

  

"General"
"0"
"0.00"
"#,##0"
"#,##0.00"
"0%"
"0.00%"
"0.00E+00"
"# ?/?"
"# ??/??"
"mm-dd-yy"
"d-mmm-yy"
"d-mmm"
"mmm-yy"
"h:mm AM/PM"
"h:mm:ss AM/PM"
"h:mm"
"h:mm:ss"
"m/d/yy h:mm"
"#,##0 ;(#,##0)"
"#,##0 ;[Red](#,##0)"
"#,##0.00;(#,##0.00)"
"#,##0.00;[Red](#,#)"
"mm:ss"
"[h]:mm:ss"
"mmss.0"
"##0.0"
"@"
上一篇:实验二 结对编程第二阶段


下一篇:Uncaught TypeError: Cannot read property 'cells' of undefined