Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exported date to Excel won't format as date
Message
From
12/05/2009 10:40:03
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01399348
Message ID:
01399394
Views:
128
This message has been marked as the solution to the initial question of the thread.
>Hi all
>
>I have a typical problem. After exporting a date field from a VFP table, say Date of Birth, into Excel, the dates that can be represented as British and American (albeit wrongly if the other way round) format well in Excel but when a date that has a day which cannot be formatted in American will not be considered for any type of date formatting in Excel, for eg.
>
>07-04-1965 (7th April 1965) will format perfectly in Excel but
>23-06-1970 (23rd June 1970) whatever I do it won't format in Excel as a date. I have tried to change the Regional settings to either and yet the problem remains for such date.
>
>Please advise what might not be gelling.

Instead of export use VFPOLEDB to 'export' the data and you wouldn't have such problem. ie:
#Define xlTop -4160
Local oExcel
oExcel = Createobject("Excel.Application")
With oExcel
  .WorkBooks.Add
  .Visible = .T.
  VFP2Excel(_samples+'data\testdata.dbc',;
    'select emp_id,first_name,last_name,'+;
    'cast(EVL(birth_date,null) as d) as birth_date,'+;
    'CAST(CHRTRAN(notes,CHR(13),"") as M) as Notes from employee',;
    .ActiveWorkBook.ActiveSheet.Range('A1'))
    
  * This part is cosmetic  
  With .ActiveWorkBook.ActiveSheet
    .UsedRange.VerticalAlignment = xlTop && set all to top
    With .Columns(5)
      .ColumnWidth = 80 && 80 chars width
      .WrapText = .T.
    Endwith
    .UsedRange.Columns.AutoFit
    .UsedRange.Rows.AutoFit
  Endwith
Endwith

Function VFP2Excel
  Lparameters tcDataSource, tcSQL, toRange
  Local loConn As AdoDB.Connection, ;
    loRS As AdoDB.Recordset,;
    ix
  loConn = Createobject("Adodb.connection")
  loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+m.tcDataSource
  loConn.Open()
  loRS = loConn.Execute(m.tcSQL)

  For ix=1 To loRS.Fields.Count
    toRange.Offset(0,m.ix-1).Value = Proper(loRS.Fields(m.ix-1).Name)
    toRange.Offset(0,m.ix-1).Font.Bold = .T.
  Endfor
  toRange.Offset(1,0).CopyFromRecordSet( loRS )
  loRS.Close
  loConn.Close
Endfunc
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform