Excel范围应用新的NumberFormat

时间:2015-06-08 18:25:35

标签: c# excel interop

我有一个Microsoft.Office.Interop.Excel.Range,我用Data填充并设置一个新的NumberFormat,如下所示:

    //Test suites
    [System.Xml.Serialization.XmlArray("TestSuites")]
    [System.Xml.Serialization.XmlArrayItem("Test", IsNullable = false)]
    public string[] Testsuites
    {
        get { return this._testSuites; }
        set { this._testSuites = value; }
    }

问题是新的NumberFormat在我点击进入单元格之前不适用。 是否存在“更新”方法或范围?!

1 个答案:

答案 0 :(得分:1)

这是因为您要将单元格值设置为string,并且在您点击进入单元格并按“输入”之前不会将其评估为日期。

Excel将日期存储为double,表示自1900年以来的时间。您应将Value2属性设置为DateTimethis example

rngExample.Value2 = new DateTime(2015, 6, 8);
rngExample.NumberFormat = "ddd, d. M";