Transfert fichier texte vers excel

dino34 Messages postés 32 Date d'inscription jeudi 6 janvier 2011 Statut Membre Dernière intervention 3 novembre 2023 - 25 déc. 2012 à 19:10
dino34 Messages postés 32 Date d'inscription jeudi 6 janvier 2011 Statut Membre Dernière intervention 3 novembre 2023 - 27 déc. 2012 à 15:30
Bonjour:

J'ai le fichier suivant créer sur macro VBA qui lit un fichier texte à l'aide de l API et transfert la fichier vers excel , et je cherche comment le faire en delphi ,c'est ma premiere expérience .


Const myPath = "C:\VILLE"
Const delim = ","

Function MergeMultipleTextFiles()
Dim myPath As String
Dim myFile As String
Dim myFile1 As String 'filename
Dim strRecord As String
Dim arrRecord1() 'record string
Dim arrRecord() 'record array
Dim fNum As Integer 'free file number
Dim RowCounter As Long
Dim RowCounter1 As Long 'row counter
Dim i As Long 'loop variable
Dim temp1 As Variant
Dim temp2 As Variant
Dim iRow As Integer
Dim m As Integer
Dim j As Integer
Dim ex As Integer
'Dim Play As Worksheet

Dim strFolderName As String

strFolderName = BrowseFolder("Choose Folder For Import")

If Len(strFolderName) > 0 Then
myPath = strFolderName
myPath = myPath & ""
Else
Resume errExit
End If

RowCounter = 0
Do While myFile <> ""
myFile1 = myFile

fNum = FreeFile
Open myPath & myFile For Input As #fNum

Do While Not EOF(fNum)
'read in the row into the record variable
Line Input #fNum, strRecord
'add the filename to the record variable
'strRecord = myFile & delim & strRecord

If strRecord <> "" And strRecord <> "INACCEPTABLE" And strRecord <> "DECALLAGE " And strRecord <> "TEMP " Then


RowCounter = RowCounter + 1
RowCounter1 = RowCounter1 + 1
'resize the record array
ReDim Preserve arrRecord(1 To RowCounter)
arrRecord(RowCounter) = strRecord
ReDim Preserve arrRecord1(1 To RowCounter1)
temp2 = Split(myFile1, ".")
arrRecord1(RowCounter1) = temp2(0)
End If

Loop

Close #fNum
'get the next file in the directory
myFile = Dir()
Loop

J'ai commencé par ceci mais je bloque dans ce qui suit:

RowCounter = RowCounter + 1
RowCounter1 = RowCounter1 + 1
'resize the record array
ReDim Preserve arrRecord(1 To RowCounter)
arrRecord(RowCounter) = strRecord
ReDim Preserve arrRecord1(1 To RowCounter1)
temp2 = Split(myFile1, ".")
arrRecord1(RowCounter1) = temp2(0)
End If

Loop

Close #fNum
'get the next file in the directory
myFile = Dir()
Loop
1/ j'ai commencé le projet par ceci:

const
FileName = 'ville.txt';
MyDir = 'C:\stat\';

procedure TForm1.Button1Click(Sender: TObject);
//* Lecture du Fichier
var
MyFileName : TFileName;
begin
MyFileName := MyDir + FileName;
ListBox1.Items.LoadFromFile(MyFileName);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
XLApp : Variant;
NbLigne : Integer;
Table1:Variant ;
MyFileName : TFileName;
begin
if MessageDlg('CONFIRMEZ EXPORTATION DE VOTRE FICHIER VERS EXCEL ?', mtConfirmation, [mbOK, mbCancel], 0) = mrOk then
begin
try
XLApp := CreateOleObject('Excel.Application');
except
ShowMessage('Démarrage de Microsoft Excel impossible');
Exit;
end;
XLApp.Visible := True;
XLApp.Workbooks.Add;

MyFileName := MyDir + FileName;

END;
end;

end.



merci pour votre aide .

4 réponses

cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
25 déc. 2012 à 21:24
Salut

"qui lit un fichier texte à l'aide de l API"
Pas besoin d'API pour cela. Bref.

"et transfert la fichier vers excel"
Transférer ? Définition.
Qu'appelles-tu transférer ?

Si tu désires de l'aide en Delphi, pourquoi poster ta question sur le site VB ?
Transféré.

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
0
dino34 Messages postés 32 Date d'inscription jeudi 6 janvier 2011 Statut Membre Dernière intervention 3 novembre 2023
27 déc. 2012 à 10:02
Bonjour:

J'ai créer le topic sur l'onglet delphi , je ne comprend pas pourquoi il était apparu dans VBA .

Le sujet est de transferer un fichier texte en utilisant delphi dans un fichier excel , le programme cité en haut c'est une macros VBA ( fonction vba) , et j'ai commençer à le faire dans delphi .

J'ai bloqué dans ce qui suit :

If strRecord <> "" And strRecord <> "INACCEPTABLE" And strRecord <> "DECALLAGE " And strRecord <> "TEMP " Then


RowCounter = RowCounter + 1
RowCounter1 = RowCounter1 + 1
'resize the record array
ReDim Preserve arrRecord(1 To RowCounter)
arrRecord(RowCounter) = strRecord
ReDim Preserve arrRecord1(1 To RowCounter1)
temp2 = Split(myFile1, ".")
arrRecord1(RowCounter1) = temp2(0)
End If

Loop

Close #fNum
'get the next file in the directory
myFile = Dir()
Loop

J'ai commencé par ceci mais je bloque dans ce qui suit:

RowCounter = RowCounter + 1
RowCounter1 = RowCounter1 + 1
'resize the record array
ReDim Preserve arrRecord(1 To RowCounter)
arrRecord(RowCounter) = strRecord
ReDim Preserve arrRecord1(1 To RowCounter1)
temp2 = Split(myFile1, ".")
arrRecord1(RowCounter1) = temp2(0)
End If

Loop

Close #fNum
'get the next file in the directory
myFile = Dir()
Loop

NB: le code en haut lit le fichier texte , ma question comment le faire en delphi en utilisant quel metode ( API WINDOWS, stringlist, INI), C-A-D
le charger dans la mémoire avec des condition ,Est ce qu'il y une fonction dans delphi qui fait ça ?


Merci pour votre aide et compréhention
0
dubois77 Messages postés 675 Date d'inscription jeudi 17 avril 2008 Statut Membre Dernière intervention 19 février 2019 14
27 déc. 2012 à 13:48
Salut Dino34
Le code que tu présentes , ce n'est toujours pas du Delphi, mais du VB à priori
Tu veux quoi au juste ?
Si tu penses que quelqu'un va te convertir ton VB en Delphi, je pense que tu peux attendre un bon bout de temps



Dubois77
site perso
0
dino34 Messages postés 32 Date d'inscription jeudi 6 janvier 2011 Statut Membre Dernière intervention 3 novembre 2023
27 déc. 2012 à 15:30
Bonjour :

J'ai commencé par ceci du vrai delphi

const
FileName = 'ville.txt';
MyDir = 'C:\stat\';

procedure TForm1.Button1Click(Sender: TObject);
//* Lecture du Fichier
var
MyFileName : TFileName;
begin
MyFileName := MyDir + FileName;
ListBox1.Items.LoadFromFile(MyFileName);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
XLApp : Variant;
NbLigne : Integer;
Table1:Variant ;
MyFileName : TFileName;
begin
if MessageDlg('CONFIRMEZ EXPORTATION DE VOTRE FICHIER VERS EXCEL ?', mtConfirmation, [mbOK, mbCancel], 0) = mrOk then
begin
try
XLApp := CreateOleObject('Excel.Application');
except
ShowMessage('Démarrage de Microsoft Excel impossible');
Exit;
end;
XLApp.Visible := True;
XLApp.Workbooks.Add;

MyFileName := MyDir + FileName;

END;
end;

end.

merci
0
Rejoignez-nous