ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

traiter des fichiers csv avec des champs memo   



L'auteur

Olivier Hamou
France France
Membre Simple
# 0000000017
enregistré le 13/10/2004
http://www.planitron.com
Hamou Olivier
94100 Saint Maur des fossés
de la société PLANITRON
Fiche personnelle


Note des membres
pas de note

Contributions > 01 - PRG : Programmation > Import - Export

traiter des fichiers csv avec des champs memo
# 0000000688
ajouté le 24/04/2009 17:39:44 et modifié le 25/04/2009
consulté 9389 fois
Niveau initié

Version(s) Foxpro :
VFP 9.0


Le téléchargement des pièces jointes est limité aux membres
Veuillez vous identifier ou vous inscrire si vous n'avez pas encore de compte ...
Description

Microsoft nous apporte deux articles à ce sujet

j'ai voulu les diffuser sur ce site afin que le maximum de personnes

puissent trouver leur bonheur.


Comment faire pour ajouter des enregistrements à partir d'un fichier délimité avec des données Mémo

http://support.microsoft.com/kb/140294

 

 

 

Comment faire pour en lecture des données de champ de note à partir des fichiers ASCII délimité

http://support.microsoft.com/kb/115731

 

 

   * DATE MODIF : 25.04.09 par olivier hamou
   * J'ai modifié le code afin que cette function
   * puisse comprendre les types de données autre que le caractère

  * variable pris en charge dans le cursor ou votre table :

  *

 

DO CASE
        CASE m.cVARTYPE $ "N-Y-B-F-I"
        REPLACE &structure[i,1] WITH VAL(accum_text)
        CASE m.cVARTYPE $ "C-M-Q-V-W"
        REPLACE &structure[i,1] WITH alltr(accum_text)
        CASE m.cVARTYPE $ "D"
        REPLACE &structure[i,1] WITH ctod(accum_text)
        CASE m.cVARTYPE $ "T"
        REPLACE &structure[i,1] WITH ctot(accum_text)
    ENDCASE

Code source :
  ***************************************************
   *  Append data from any delimited ASCII file into
   *  a predefined FoxPro database file. The intent
   *  is to read in memo field data, but the program
   *  will also address files with varying delimiters.
   *  This program assumes that the target database
   *  file is currently in use, used exclusively, and
   *  in the current work area.
   *
   * DATE MODIF : 25.04.09 par olivier hamou
   * J'ai modifié le code afin que cette function
   * puisse comprendre les types de données autre que le caractère
   ***************************************************
Function AppendData
   PARAMETERS text_file, char_delimiter, field_delimiter

   ***************************************************
   *  Create an array of database structure.
   *  Determine number of records in array for FOR
   *  loop counting.
   ***************************************************
   =AFIELDS(structure)
   rows = ALEN(structure,1)

   ***************************************************
   *  Attempt to open text file with low-level handle.
   *  If the test is successful, continue; otherwise,
   *  report reason for failure.
   ***************************************************
   file_handle = FOPEN(text_file)
   IF file_handle < 0
      DO errhand WITH FERROR()
      RETURN .F.
   ENDIF

   ***************************************************
   *  Begin DO WHILE loop and continue until end of
   *  file marker is reached in text file.
   ***************************************************
   DO WHILE !FEOF(file_handle)
      APPEND BLANK
      FOR i = 1 TO rows
         && Messagebox(structure[i,2])
         && ANCIEN CODE MICROSOFT
         &&IF structure[i,2] $ "N-Y-B-F-I"
         && =readnum("",0)
         &&ELSE
       && =readchar("",0)
         &&ENDIF
         && modifié par olivier
         =readchar("",0,structure[i,2])
      ENDFOR
   ENDDO
   =FCLOSE(file_handle)


   ***************************************************
   *  Read numeric field data into corresponding
   *  field in database.
   ************************************************
   FUNCTION readnum
   PARAMETERS accum_text, count_comma
   DO WHILE count_comma < 1
      single = FREAD(file_handle,1)
      IF single = field_delimiter OR single = CHR(13)
         single = ""
         count_comma = count_comma + 1
         IF count_comma < 1 AND i > rows
            =FSEEK(file_handle,1,1)
         ENDIF
      ELSE
         accum_text = accum_text + single
      ENDIF
   ENDDO
   Messagebox(accum_text)
   REPLACE &structure[i,1] WITH VAL(accum_text)
   accum_text = ""
   RETURN

   ***************************************************
   *  Read all field types in as character except
   *  numeric fields.
   ***************************************************
  FUNCTION readchar
  PARAMETERS accum_text, count_quotes ,cVARTYPE
  DO WHILE count_quotes < 2 AND !FEOF(file_handle)
    single = FREAD(file_handle,1)
    IF single = char_delimiter
      single = ""
      count_quotes = count_quotes + 1
      IF count_quotes >= 2
        x=FREAD(file_handle,1)
        IF x = CHR(13)
          =FSEEK(file_handle,1,1)
        ENDIF
      ENDIF
    ELSE
      accum_text = accum_text + single
    ENDIF
  ENDDO
  &&messagebox(structure[i,1]+" "+accum_text)
  DO CASE
    CASE m.cVARTYPE $ "N-Y-B-F-I"
    REPLACE (structure[i,1]WITH VAL(accum_text)
    CASE m.cVARTYPE $ "C-M-Q-V-W"
    REPLACE (structure[i,1]WITH alltr(accum_text)
    CASE m.cVARTYPE $ "D"
    REPLACE (structure[i,1]WITH ctod(accum_text)
    CASE m.cVARTYPE $ "T"
    REPLACE (structure[i,1]WITH ctot(accum_text)
  ENDCASE
  accum_text = ""
  RETURN
   ***************************************************
   *  Error handling routine
   ***************************************************
   FUNCTION errhand
   PARAMETERS error
   DO CASE
      CASE error = 2
         reason = "File not found"
      CASE error = 4
         reason = "Too many files open"
      CASE error = 5
         reason = "File access denied"
      CASE error = 6
         reason = "Invalid file handle given"
      CASE error = 8
         reason = "Out of memory"
      CASE error = 25
         reason = "Seek error (can't seek before start of file)"
      CASE error = 29
         reason = "Disk is full"
      CASE error = 31
         reason = "Error opening file"
   ENDCASE
   WAIT WINDOW "Cannot open file: "+reason
EndFunc
Commentaires
Aucun commentaire enregistré ...

Publicité

Les pubs en cours :


www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2024.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3