BlackLanzer / excellibrary

Automatically exported from code.google.com/p/excellibrary
0 stars 0 forks source link

DataSetHelper.CreateWorkbook uses 1904 Date system #76

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create Dataset
2. Save dataset using ExcelLibrary.DataSetHelper.CreateWorkbook
3. Open workbook in Excel

What is the expected output? What do you see instead?
Standard excel behaviour is to create workbooks not using the 1904 date system, 
workbooks using this library do use the 1904 date system (in Excel options you 
can see this).  Other than that, it's perfect.

What version of the product are you using? On what operating system?
Windows XP with Office 2007

Please provide any additional information below.

Original issue reported on code.google.com by garethte...@gmail.com on 26 Oct 2010 at 2:06

GoogleCodeExporter commented 8 years ago
http://support.microsoft.com/kb/214330

Original comment by garethte...@gmail.com on 26 Oct 2010 at 2:10

GoogleCodeExporter commented 8 years ago
Just the option to create it with or without would be ideal as 1904 dates are 
valid in some cases, just not mine.

Thanks

Original comment by garethte...@gmail.com on 26 Oct 2010 at 2:12

GoogleCodeExporter commented 8 years ago
I have developed a solution to this issue that allows you to set the date mode 
on the workbooks that you create with this ExcelLibrary.

1) In Workbook.cs, add the following property inside the Workbook class 
definition:

  public Int16 DateMode;

2) In WorkbookEncoder.cs, make the following changes inside the EncodeWorkbook 
function:
Replace these two lines:

  dateMode = 1;
  sharedResource.BaseDate = DateTime.Parse("1904-01-01");

with 

  dateMode.Mode = workbook.DateMode;
  sharedResource.BaseDate = workbook.DateMode == 1 ? DateTime.Parse("1904-01-01") : DateTime.Parse("1899-12-30");

3) This will allow you to choose either the 1904 date format (DateMode = 1) or 
the 1900 date format (DateMode = 0) from your class that uses the ExcelLibrary 
solution. For example, if your instance of your Workbook is called "workbook", 
then you would set the property in the following way, anytime before you call 
workbook.Save:

  workbook.DateMode = 0;

Original comment by jamielmi...@gmail.com on 17 Dec 2010 at 3:32

GoogleCodeExporter commented 8 years ago
Why DateTime.Parse("1899-12-30") not DateTime.Parse("1900-01-01") for 1900 date 
mode?

Original comment by China.LiuJunFeng on 14 Apr 2011 at 12:24

GoogleCodeExporter commented 8 years ago
Because excel thinks 1900 is a leap year, thus assuming it has one more day 
than it really does. This cascades to make all dates miss by one day. Using 
12/31/1989 is a way of compensating.

Original comment by Eric.Yar...@gmail.com on 3 Aug 2011 at 3:45