Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Export to excel . blank dates have dashes
Message
De
05/06/2006 13:22:58
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
05/06/2006 12:23:28
David Klein
National Care Systems, Llc
Brooklyn, New York, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01127128
Message ID:
01127144
Vues:
10
>hi all. when i try to export any cursor/dbf to excel, blank dates are coming up with dashes in excel file. is there any work around to get rid of dashes either in vfp or on excel end? thanks for help in advance.

Use nulls for empty dates. ie:
Select emp_id,First_Name,Last_Name,;
  Iif(Year(Birth_Date)<1950,.Null.,Birth_Date) As Birth_Date,;
  Title,Notes ;
  from (Home()+'samples\data\employee') ;
  into Cursor crsToExcel ;
  nofilter


oExcel = Createobject("Excel.Application")
With oExcel
  .Workbooks.Add
  .Visible = .T.
  With .ActiveWorkBook.ActiveSheet
    VFP2Excel(oExcel, 'crsToExcel', .Name, "A1")
  Endwith
Endwith

Function VFP2Excel
  Lparameters toExcel, tcCursorName, tcSheetName, tcRange
  tcCursorName = Iif(Empty(m.tcCursorName),Alias(),m.tcCursorName)
  tcSheetName = Iif(Empty(m.tcSheetName),"Sheet1", m.tcSheetName)
  Local loConn As AdoDB.Connection, loRS As AdoDB.Recordset,;
    lcTempRs, lcTemp, oExcel
  lcTemp = Forcepath(Sys(2015)+'.dbf',Sys(2023))
  lcTempRs = Forcepath(Sys(2015)+'.rst',Sys(2023))
  Select (m.tcCursorName)
  Copy To (m.lcTemp)
  loConn = Createobject("Adodb.connection")
  loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+Sys(2023)
  loConn.Open()
  loRS = loConn.Execute("select * from "+m.lcTemp)
  loRS.Save(m.lcTempRs)
  loRS.Close
  loConn.Close
  Erase (m.lcTemp)
  loRS.Open(m.lcTempRs)

  With toExcel.WorkSheets( ;
      Iif(Empty(m.tcSheetName),;
      .ActiveWorkBook.ActiveSheet.Name, ;
      m.tcSheetName))
    .QueryTables.Add( loRS, .Range(m.tcRange)).Refresh()
  Endwith
  loRS.Close
  Erase (m.lcTempRs)
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform