Question : Exporting to Excel From Visual Foxpro Excel Object Creating 2 Digit Year, Not 4 Digit

HI All,

I am exporting a DBF to an EXCEL file and the dates are not going into Excel correctly.

The date settings are correct for long and short date in Regional settings in Windows.

Client is running Windows XP Service Pack 3, Excel 2003, VFP7, VFP ODBC Driver 6.01.8629.01

If I send a CHAR(10) column for the date as "02/01/1945" The excel file will show a 2 digit year "02/01/45"

If I send a DATE type column for the date as {02/01/1945}, Excel will show it as 02/01/2045.

If I send a DATETIME type column for the date as {02/01/1945 00:00:00}, Excel will show it as 02/01/2045 0:00.

If I try to click on the column in Excel to change the format when I send the CHAR(10) date, It does not even allow me to change the format.

Best part of this whole thing is that it works fine on my 2 dev stations using all the same versions of software.

Are there any other settings I am missing in Excel to make sure the date is interpreted correctly when exporting using the Excel applicaion object?

I am using the object to be able to go up to 65000 lines...

Thank you,

Chris W
631-521-9100
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
ObjExcel= CREATEOBJECT("Excel.Application")
*ObjExcel.DisplayAlerts = .f.

wb = ObjExcel.Workbooks.add()

ConnectionString="ODBC;DSN=Visual FoxPro Tables Download;UID=;PWD="

sqlquery="SELECT * from c:\netelite\lctrans1"

ObjExcel.ActiveSheet.QueryTables.Add(;
ConnectionString,;
ObjExcel.ActiveSheet.Range("A1"),;
sqlquery)

ObjExcel.ActiveSheet.QueryTables(1).BackgroundQuery = .f.
ObjExcel.ActiveSheet.QueryTables(1).Refresh

ObjExcel.ActiveSheet.Range("A1").Select    

SET SAFETY OFF
mfileexcel = mfile

IF FILE(mfileexcel)
	DELETE FILE &mfileexcel
ENDIF

wb.SaveAs(mfileexcel)

ObjExcel.Quit()

Answer : Exporting to Excel From Visual Foxpro Excel Object Creating 2 Digit Year, Not 4 Digit

To force VFP ODBC driver to return two digits year is possible when you return the date as a character string only. Excel then decides how to display it.

When the date is returned as date or datetime data type then you cannot affect the number of digits in its year part but you should be able to format it in Excel.

Incorrect century is purely Excel problem because ODBC driver is returning it correctly and you should check installed Excel service packs and/or ask in Excel zone eventually.

Random Solutions  
 
programming4us programming4us