Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dbf2rs
Message
De
13/09/2010 07:41:05
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
10/09/2010 05:15:22
Jon Neale
Bond International Software
Wootton Bassett, Royaume Uni
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Re: Dbf2rs
Versions des environnements
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01480753
Message ID:
01480943
Vues:
119
This message has been marked as the solution to the initial question of the thread.
>Hi All,
>
>I have implemented Cetin Basoz's export to excel functionality and it has been working very well. However I have noticed something and was hoping for some feedback, the issue is actually with Dbf2rs not the additional code kindly posted by Cetin. When I export a numeric value it changes the decimals, so for example if I export 11000.03 it changes it in excel to 11000.0302734373. I believe the issue to be with the recordset not excel as I can see the value has changed when its entered into the recordset. The type for the field in the rs is ADSINGLE.
>
>Is there anyway I can prevent this or improve the way this works?
>
>Many Thanks
>
>Jon

Jon,
It would work with the original code using VFPOLEDB or it would work if you haven't used numeric as a data type (instead use something like B(2), Y):
CREATE CURSOR test (myID i, myValue n(10,2))
INSERT INTO test VALUES (1, 11000.03)


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

Function VFP2Excel
  Lparameters tcCursorName, toRange, tcHeaders
  tcCursorName = Iif(Empty(m.tcCursorName),Alias(),m.tcCursorName)
  Local loConn As AdoDB.Connection, loRS As AdoDB.Recordset,;
    lcTemp, oExcel,ix

  lcTemp = Forcepath(Sys(2015)+'.dbf',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)

  * Use first row for headers
  Local Array aHeader[1]

  toRange.Offset(1,0).CopyFromRecordSet( loRS )  && Copy data starting from headerrow + 1
  For ix=1 To Iif( !Empty(m.tcHeaders), ;
      ALINES(aHeader, m.tcHeaders,1,','), ;
      loRS.Fields.Count )
    toRange.Offset(0,m.ix-1).Value = ;
      Iif( !Empty(m.tcHeaders), ;
      aHeader[m.ix], ;
      Proper(loRS.Fields(m.ix-1).Name) )
    toRange.Offset(0,m.ix-1).Font.Bold = .T.
  Endfor

  loRS.Close
  loConn.Close
  Erase (m.lcTemp)
Endfunc
PS: Why are you trying to create your own RS when there is VFPOLEDB.
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform