Excel Interop Range.Value = arr 当arr 包含date小于1900-01-01时与0x800A03EC崩溃

我理解的基本问题是,Excel表示1900-01-01为1的值。但是,在Excel中可以手动input1900以前的值。

// this converts the DataTable to an Object[,] DataTable table = ... Object[,] arr = DataTableUtils.toObjectArray(table, false); Range r00 = r0.get_Resize(arr.GetLength(0), arr.GetLength(1)); r00.Value = arr; // <-- this will crash if ... 

如果arr [,]在1899-12-31之前包含DateTime对象,则会导致0x800A03ECexception。 奇怪的是,1899-12-31很好,Excel增加了一天的价值。 最初我用1900-01-01replace了1900年前的date,但在输出文件中,它们是1900-01-02!

目前,我正在使用解决方法来replace错误的DateTime值。 但是,如果有人有更好的解决scheme,请让我知道。