Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > PEAR
PEAR Forum d'entraide sur le framework PHP : PEAR. Avant de poster -> cours PEAR.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 26/05/2008, 19h50   #1
Candidat au titre de Membre du Club
 
Inscription : décembre 2003
Messages : 44
Détails du profil
Informations forums :
Inscription : décembre 2003
Messages : 44
Points : 11
Points : 11
Envoyer un message via AIM à kitana Envoyer un message via MSN à kitana
Par défaut Lecture fichier Excel : PHP-ExcelReader

Bonjour,

j'utilise un cette librairie pour lire les données d'un fichier excel.
Sur mon serveur local (wamp). je n'ai aucun probleme.

par contre une fois que je passe ce script sur mon serveur de developpement (redhat entreprise),
j'ai une erreur qui dit que le fichier n'est pas accessible en lecture.
Apres debuggage, c'est cette portion de code
Code :
1
2
3
4
5
6
 
if (substr($this->data, 0, 8) != IDENTIFIER_OLE) {
			echo substr($this->data, 0, 8);
    		$this->error = 1; 
    		return false; 
   		}
de la fonction de lecture qui retourne une erreur.
en effet quand j'affiche les deux valeurs sur mon serveur local, j'ai exactement les mêmes données pour la constante IDENTIFIER_OLE et les premiers bits lus dans la chaine récupérée dans le fichier.
or sur mon dev, il y a des caractères en plus.

Quelqu'un aurait une idée pour la cause du problème?

MErci d'avance.


Ci dessous le code de la fonction.:

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 
define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));
 
 function read($sFileName){
 
    	// check if file exist and is readable (Darko Miljanovic)
    	if(!is_readable($sFileName)) {
 
    		$this->error = 1;
    		return false;
    	}
 
    	$this->data = @file_get_contents($sFileName);
    	if (!$this->data) { 
 
    		$this->error = 1; 
    		return false; 
   		}
 
   		if (substr($this->data, 0, 8) != IDENTIFIER_OLE) {
 
    		$this->error = 1; 
    		return false; 
   		}
        $this->numBigBlockDepotBlocks = GetInt4d($this->data, NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
        $this->sbdStartBlock = GetInt4d($this->data, SMALL_BLOCK_DEPOT_BLOCK_POS);
        $this->rootStartBlock = GetInt4d($this->data, ROOT_START_BLOCK_POS);
        $this->extensionBlock = GetInt4d($this->data, EXTENSION_BLOCK_POS);
        $this->numExtensionBlocks = GetInt4d($this->data, NUM_EXTENSION_BLOCK_POS);
 
 
 
        $bigBlockDepotBlocks = array();
        $pos = BIG_BLOCK_DEPOT_BLOCKS_POS;
 
	$bbdBlocks = $this->numBigBlockDepotBlocks;
 
            if ($this->numExtensionBlocks != 0) {
                $bbdBlocks = (BIG_BLOCK_SIZE - BIG_BLOCK_DEPOT_BLOCKS_POS)/4; 
            }
 
        for ($i = 0; $i < $bbdBlocks; $i++) {
              $bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);
              $pos += 4;
        }
 
 
        for ($j = 0; $j < $this->numExtensionBlocks; $j++) {
            $pos = ($this->extensionBlock + 1) * BIG_BLOCK_SIZE;
            $blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, BIG_BLOCK_SIZE / 4 - 1);
 
            for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; $i++) {
                $bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);
                $pos += 4;
            }   
 
            $bbdBlocks += $blocksToRead;
            if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
                $this->extensionBlock = GetInt4d($this->data, $pos);
            }
        }
 
       // var_dump($bigBlockDepotBlocks);
 
        // readBigBlockDepot
        $pos = 0;
        $index = 0;
        $this->bigBlockChain = array();
 
        for ($i = 0; $i < $this->numBigBlockDepotBlocks; $i++) {
            $pos = ($bigBlockDepotBlocks[$i] + 1) * BIG_BLOCK_SIZE;
            //echo "pos = $pos";	
            for ($j = 0 ; $j < BIG_BLOCK_SIZE / 4; $j++) {
                $this->bigBlockChain[$index] = GetInt4d($this->data, $pos);
                $pos += 4 ;
                $index++;
            }
        }
 
	//var_dump($this->bigBlockChain);
        //echo '=====2';
        // readSmallBlockDepot();
        $pos = 0;
	    $index = 0;
	    $sbdBlock = $this->sbdStartBlock;
	    $this->smallBlockChain = array();
 
	    while ($sbdBlock != -2) {
 
	      $pos = ($sbdBlock + 1) * BIG_BLOCK_SIZE;
 
	      for ($j = 0; $j < BIG_BLOCK_SIZE / 4; $j++) {
	        $this->smallBlockChain[$index] = GetInt4d($this->data, $pos);
	        $pos += 4;
	        $index++;
	      }
 
	      $sbdBlock = $this->bigBlockChain[$sbdBlock];
	    }
 
 
        // readData(rootStartBlock)
        $block = $this->rootStartBlock;
        $pos = 0;
        $this->entry = $this->__readData($block);
 
        /*
        while ($block != -2)  {
            $pos = ($block + 1) * BIG_BLOCK_SIZE;
            $this->entry = $this->entry.substr($this->data, $pos, BIG_BLOCK_SIZE);
            $block = $this->bigBlockChain[$block];
        }
        */
        //echo '==='.$this->entry."===";
        $this->__readPropertySets();
 
    }
kitana est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/06/2008, 16h11   #2
Invité de passage
 
Inscription : juin 2008
Messages : 1
Détails du profil
Informations forums :
Inscription : juin 2008
Messages : 1
Points : 1
Points : 1
Par défaut Pb Excel

Bonjour,

ça peut peut etre en aider certains, j'ai eu récemment ce problème et il s'avère que ça venait tout simplement du fichier uploadé.

La constante IDENTIFIER_OLE vérifie s'il s'agit bien d'un fichier excel, et certaines manip d'import / export peuvent générer des .html au lieu .xls

Veillez donc à manipuler de "vrais" fichiers excel.

En espérant avoir été clair et que ça en aidera certains
BurningFire est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/04/2009, 18h45   #3
Membre à l'essai
 
Avatar de med_ellouze
 
Étudiant
Inscription : mai 2006
Messages : 89
Détails du profil
Informations personnelles :
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : mai 2006
Messages : 89
Points : 23
Points : 23
Envoyer un message via MSN à med_ellouze Envoyer un message via Yahoo à med_ellouze Envoyer un message via Skype™ à med_ellouze
St BurningFire,
J'ai le même problème que toi et pourtant j'ai bien un fichier excel sauf qu'il s'agit d'une ancienne version.
J'utilise la librairie writeexcel pour générer mon fichier excel et ensuite j'utilise la librairie spreadsheet_excel reader pour importer mon fichier.
J'ai constaté qu'en ouvrant le fichier exporté et en faisant un save, je pourrais importer mes données (sachant qu'au moment de la sauvegarde une popup s'affiche m'indiquant le message suivant : (MonFichier.xls is a Microsoft Excel 5.0/95 Workbook. Do you want to overwrite it with the latest Excel format?) sinon, si je fais pas de save, j'arrive pas à insérer mes données.

As tu une idée là dessus pour ne plus être obligé de faire un save à l'avant pour pouvoir importer mon fichier.

d'avance merci
med_ellouze est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 17h35.


 
 
 
 
Partenaires

Hébergement Web