|
|
|
|
Bonjour. Voilà, j'ai un soucis avec mon script de Perl. Il a pour but de récupérer des données d'un fichier excel et de les retranscrire dans un fichier csv. Mon souci est au niveau de la récupération des données. Ils me les retranscrit bien, mais pas qu'une fois, il le fait plusieurs fois, il boucle les données une quinzaine de fois alors que je veux qu'il le fasse qu'une fois.
Pour moi, il y a un soucis au niveau des boucles, mais je n'arrive pas à le corriger et comme je débute en programmation, ça commence à me prendre la tête.
Je vous mets ci-dessous mon code. Merci de vouloir y jeter un oeil.
#!C:/Perl/bin/perl.exe
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $excel_in = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $book = $excel_in->Workbooks->Open("C:\\Clients\\Systeme_U\\marketing_distinctif\\produits_SU1107.xls");
my $sheet = $book->Worksheets(1);
my $array1 = $sheet->Range("A3:A167" )->{'Value'};
my $array2 = $sheet->Range("B3:B167" )->{'Value'};
my $sheet2 = $book->Worksheet(2);
$book->Close;
foreach my $ref_array1 (@$array1) {
foreach my $ref_array2 (@$array2) {
foreach my $scalar1 (@$ref_array1) {
foreach my $scalar2 (@$ref_array2) {
my $ligne=0;
foreach my $word1 ( split(' ',$scalar1) ) {
foreach my $word2 ( split(' ',$scalar2) ) {
print "$word1;$word2\n";
my $fichier= "C:\\Clients\\Systeme_U\\marketing_distinctif\\produits_SU1107.csv";
open F, ">>$fichier"; # ouverture en ajout dans un fichier existant
print F "$word1;$word2\n"; # écriture de $chaine dans le fichier
}
}
$ligne++;
}
}
}
}
close F;
print "File Completed\n";
system("pause");
Configuration: Windows XP Firefox 2.0.0.7
Salut,
#!C:/Perl/bin/perl.exe
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $excel_in = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $book = $excel_in->Workbooks->Open("C:\\Clients\\Systeme_U\\marketing_distinctif\\produits_SU1107.xls");
my $sheet = $book->Worksheets(1);
my $array1 = $sheet->Range("A3:A167" )->{'Value'};
my $array2 = $sheet->Range("B3:B167" )->{'Value'};
my $sheet2 = $book->Worksheet(2);
$book->Close;
my $fichier= "C:\\Clients\\Systeme_U\\marketing_distinctif\\produits_SU1107.csv";
open F, ">>$fichier"; # ouverture en ajout dans un fichier existant
my @x = split " ", join " ",map { split } @$array1;
my @y = split " ", join " ",map { split } @$array2;
print F "$x[$_];$y[$_]\n" for (0..$#x)
close F;
print "File Completed\n";
system("pause");
__END__
lami20j |
Et mois j'ai besoin que tu m'envoies ton fichier excel pour tester.
#!C:/Perl/bin/perl.exe
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $excel_in = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $book = $excel_in->Workbooks->Open("C:\\Clients\\Systeme_U\\marketing_distinctif\\produits_SU1107.xls");
my $sheet = $book->Worksheets(1);
my $array1 = $sheet->Range("A3:A167" )->{'Value'};
my $array2 = $sheet->Range("B3:B167" )->{'Value'};
my $sheet2 = $book->Worksheet(2);
$book->Close;
for (@$array1){ print "-$_\n";}
for (@$array2){ print "=$_\n";}
__END__execute ensuite le fichier avec la commande
perl script.pl > c:\resultat.txtet mets le fichier resultat.txt sur cjoint.com lami20j |
Je vais avoir du mal avec ton dernier code à te passer un fichier de sortie car il n'en crée pas, vu qu'il n'y a pas de code concernant la sortie. Donc j'insère le mien pour avoir une sortie, et là il ne me retranscrit rien. Mon csv est vide. Mais là n'est pas le soucis.
|
Je vais avoir du mal avec ton dernier code à te passer un fichier de sortie car il n'en crée pas, vu qu'il n'y a pas de code concernant la sortie.
#!C:/Perl/bin/perl.exe
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $excel_in = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $book = $excel_in->Workbooks->Open("C:\\Clients\\Systeme_U\\marketing_distinctif\\produits_SU1107.xls");
my $sheet = $book->Worksheets(1);
my $array1 = $sheet->Range("A3:A167" )->{'Value'};
my $array2 = $sheet->Range("B3:B167" )->{'Value'};
my $sheet2 = $book->Worksheet(2);
$book->Close;
open F,">>c:\resultat.txt"
or die "E/S : $!\n";
for (@$array1){ print F "-$_\n";}
for (@$array2){ print F "=$_\n";}
__END__J'attends ton retour
Mon code et fonctionnel. En revanche ça depends de ce que les cellules contiennent. Si tu ne peux pas me dire, je ne pourrai pas t'aider. lami20j |
http://cjoint.com/?kcrtrZOsQV pour le fichier .xls
|
#!C:/Perl/bin/perl.exe
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $excel_in = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $book = $excel_in->Workbooks->Open("C:\\Clients\\Systeme_U\\marketing_distinctif\\produits_SU1107.xls");
my $sheet = $book->Worksheets(1);
my $array1 = $sheet->Range("A3:A167" )->{'Value'};
my $array2 = $sheet->Range("B3:B167" )->{'Value'};
my $sheet2 = $book->Worksheet(2);
$book->Close;
open F,">>c:\resultat2.txt"
or die "E/S : $!\n";
for (@$array1){ print F "-@$_\n";}
for (@$array2){ print F "=@$_\n";}exécute et mets aussi le fichier resultat2txt sur cjoint.com
lami20j |
#!C:/Perl/bin/perl.exe
use strict;use warnings;
use Spreadsheet::ParseExcel;
open F,">>c:\resultat.csv"
or die "E/S : $!\n";
my $file = "C:\\Clients\\Systeme_U\\marketing_distinctif\\produits_SU1107.xls";
my $excel = Spreadsheet::ParseExcel::Workbook->Parse($file);
my $sheet = ${$excel->{Worksheet}}[0];
foreach my $row (2 ... 166) {
my $cell1 = $sheet->{Cells}[$row][0];
my $cell2 = $sheet->{Cells}[$row][1];
print F "$cell1->{Val};$cell2->{Val}\n";
}
__END__--
lami20j |