[Excel] Modification de plusieurs fichiers excel
Bonjour,
J'ai pour mission de créer un script pour ajouter des informations provenant de ma base de données dans plusieurs fichiers excel (385 fichiers plus précisément).
Mon script :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| $DB = new DB(); // CLASSE BDD
// APP_ROOT = dossier courant
$dirname = APP_ROOT.'applications/editions/'; // LIEN DES BILANS EXCEL
$dir = opendir($dirname); // OUVERTURE DOSSIER
$tabFile = array(); // INITIALISATION TABLEAU DE FICHIER
while($file = readdir($dir)) { // RECUPERATION FICHIER ET INSERTION DANS UN TABLEAU
if(pathinfo($file, PATHINFO_EXTENSION) == 'xls')
{
$tabFile[] = $file; // INSERTION NOM DU FICHIER DANS TABLEAU
}
}
$cpt = 0;
while($cpt < count($tabFile)) // BOUCLE SUR TABLEAU DE FICHIER
{
// echo $dirname.$tabFile[$cpt]." ------- ".file_exists($dirname.$tabFile[$cpt])."<br />";
$objet = PHPExcel_IOFactory::createReader('Excel5');
$excel = $objet->load($dirname.$tabFile[$cpt]); // CHARGEMENT FICHIER
$sheet = $excel->getSheetByName("Feuil2"); // FEUILLE A MODIFIER
$tabVar = array(); // TABLEAU DE VARIABLE
$fin = false; // SI FIN DES DONNEES
$c = 3; // N° DE LIGNE COMMENCEMENT
while($fin == false)
{
if($sheet->getCell( 'B'.$c )->getValue() == "") // S IL N'Y A PLUS DE DONNEE
{
$fin = true; // FIN
}
else
{
$tabVar[$c] = $sheet->getCell( 'B'.$c )->getValue(); // RECUPERER DONNEE POUR REQUETE
$c++;
}
}
$i = 3; // N° ligne commencement
while($i < $c) {
$req = "SELECT var_nl, var_nc FROM Variables WHERE var_nc = '".$tabVar[$i]."'"; // RECUPERER DONNEE DANS BDD
$res = $DB->query($req);
while($row = $DB->fetch_array($res))
{
$sheet->setCellValue('H'.$i, $row['var_nl']); // INSERER DANS CELLULE
}
$i++;
}
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$writer->save($dirname.$tabFile[$cpt]);
echo "Modification fichier : ".$dirname.$tabFile[$cpt]."<br />";
$cpt++;
}
closedir($dir); |
Malheuresement, plusieurs problèmes se pose :
- Il n'y a que les 3 premiers fichiers qui sont modifiés, sa affiche ensuite l'erreur "Notice: Undefined property: PHPExcel_Calculation::$_savedPrecision in PHPExcel\Calculation.php on line 1739"
- Il manque des éléments dans mon fichiers après enregistrement (dans la feuille1)
J'ai l'impression que cela vient de la taille des fichiers, car si je force le script à modifier le 4ème fichier(qui fait 1mo), rien ne marche.
Mais par exemple si je force le script à modifier le 8ème fichier (qui fait 40ko), sa marche
Je suis un peu débutante en phpExcel, je le précise...
Merci
EDIT : mon fichier log m'indique "Cell coordinate can not be zero-length string"