IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[PEAR] Lecture fichier Excel : PHP-ExcelReader


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Nouveau membre du Club
    Inscrit en
    Décembre 2003
    Messages
    44
    Détails du profil
    Informations forums :
    Inscription : Décembre 2003
    Messages : 44
    Points : 36
    Points
    36
    Par défaut [PEAR] 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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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();
     
        }

  2. #2
    Nouveau Candidat au Club
    Inscrit en
    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

  3. #3
    Membre du Club Avatar de med_ellouze
    Profil pro
    Étudiant
    Inscrit en
    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 : 52
    Points
    52
    Par défaut
    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

Discussions similaires

  1. [PHP 5.3] lecture fichier Excel dans PHP
    Par anissa2 dans le forum Langage
    Réponses: 7
    Dernier message: 25/09/2013, 14h49
  2. [Excel] Lecture fichiers Excel sans Excel
    Par neometaller dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 26/04/2007, 09h32
  3. Lecture fichier Excel
    Par marie20 dans le forum C++Builder
    Réponses: 4
    Dernier message: 27/03/2007, 15h02
  4. [VB.net] Lecture fichier excel, cellule fusionnée
    Par UNi[FR] dans le forum Windows Forms
    Réponses: 1
    Dernier message: 16/08/2006, 13h12
  5. [Excel] Comment afficher les données d'un fichier Excel (PHP)
    Par pierrot10 dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 11/05/2006, 15h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo