Permalink
Browse files

datetime utils

  • Loading branch information...
1 parent c4e4f44 commit a2a38f07462f6290d0c0a700f67824e788eff63f @mstijak mstijak committed Nov 17, 2011
@@ -99,6 +99,7 @@
<Compile Include="Workbook.IO.cs" />
<Compile Include="IO\XlsxFileReader.cs" />
<Compile Include="SheetRange.cs" />
+ <Compile Include="XlioUtil.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
@@ -42,7 +42,7 @@ private void ReadSheet(string sheetPath, Sheet sheet)
{
case ST_CellType.n:
var n = Convert.ToDouble(c.v);
- value = data.style != null && NumberFormat.IsDateTimeFormat(data.style.format) ? value = Util.ToDateTime(n) : n;
+ value = data.style != null && NumberFormat.IsDateTimeFormat(data.style.format) ? value = XlioUtil.ToDateTime(n) : n;
break;
case ST_CellType.inlineStr:
value = c.v;
@@ -299,7 +299,7 @@ private string WriteCellValue(CellData data, out ST_CellType ct, out String valu
if (type == typeof(DateTime))
{
ct = ST_CellType.n;
- return value = String.Format(CultureInfo.InvariantCulture, "{0}", Util.ToExcelDateTime((DateTime)data.Value));
+ return value = String.Format(CultureInfo.InvariantCulture, "{0}", XlioUtil.ToExcelDateTime((DateTime)data.Value));
}
if (type == typeof(string))
{
@@ -17,21 +17,5 @@ public static bool TryCast<T>(object o, out T t)
t = default(T);
return false;
}
-
- static readonly DateTime baseDate = new DateTime(1899, 12, 31);
-
- public static DateTime ToDateTime(double excelDateTime)
- {
- if (excelDateTime > 59) excelDateTime -= 1; //Excel/Lotus 2/29/1900 bug
- return baseDate.AddDays(excelDateTime);
- }
-
- public static double ToExcelDateTime(DateTime dateTime)
- {
- var res = (dateTime - baseDate).TotalDays;
- if (res > 58)
- res += 1;
- return res;
- }
}
}
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Codaxy.Xlio
+{
+ public class XlioUtil
+ {
+ static readonly DateTime baseDate = new DateTime(1899, 12, 31);
+
+ public static DateTime ToDateTime(double excelDateTime)
+ {
+ if (excelDateTime > 59) excelDateTime -= 1; //Excel/Lotus 2/29/1900 bug
+ return baseDate.AddDays(excelDateTime);
+ }
+
+ public static double ToExcelDateTime(DateTime dateTime)
+ {
+ var res = (dateTime - baseDate).TotalDays;
+ if (res > 58)
+ res += 1;
+ return res;
+ }
+ }
+}
@@ -3,7 +3,7 @@
<metadata schemaVersion="2">
<id>Codaxy.Xlio</id>
<title>Codaxy Excel IO Library</title>
- <version>0.8.5</version>
+ <version>0.8.6</version>
<authors>Codaxy</authors>
<description>Codaxy Excel IO library provides useful tool for rading/writing Excel files.</description>
<dependencies>

0 comments on commit a2a38f0

Please sign in to comment.