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

Langage PHP Discussion :

affichage fichier excel


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    338
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 338
    Par défaut affichage fichier excel
    Bonjour,

    J'essaye de lire un fichier excel. Je me suis aider de : http://sourceforge.net/projects/phpexcelreader/. J'ai tester sa marche mais je n'arrive pas a l'adapter a mon code. La réponse qui m'est retourné est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    The filename jxlrwtest.xls is not readable
    . J'utilise pourtant le même fichier excel que pour mais test. Le fichier excel est situé au même endroit que mon fichier php.

    J'utilise codeigniter.

    Voici mon code:

    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
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
     
    function do_upload(){
        // Configuration upload de fichier
        $config['upload_path'] = './application/controllers/fichier/'; // dossier où l'on stocke les fichiers
        $config['allowed_types'] = 'xls|xlsx'; // type de fichiers, ici des images
     
     $this->load->library('upload', $config);
        // Si l'upload n'a pas réussi, on renvoit une erreur (1)
        if(!$this->upload->do_upload()):
                        // Important : les erreurs renvoyées par CodeIgniter sont pré-formatées en HTML, on vire donc les tags
            $erreur = strip_tags($this->upload->display_errors());
            // On prépare une array...
            $reponse['erreur'] = 1;
            $reponse['message'] = $erreur;
            // On fait l'echo de l'array en encodant en json
            echo json_encode($reponse);
        else:
            // Si le fichier a bien été uploadé, on renvoit 0 en erreur + les infos du fichier
            $fileInfos = array('upload_data' => $this->upload->data()); // On crée une array pour faciliter la récupération d'infos fichier
            $excel = base_url().'excel/'.$fileInfos['upload_data']['file_name']; // On va renvoyer ici l'adresse du fichier
            // On prépare une array...
            $reponse['erreur'] = 0;
            $reponse['excel'] = $excel;
     
    		//lecture du fichier  excel
    		// Test CVS
    	$allow_url_override = 1; // Set to 0 to not allow changed VIA POST or GET
    if(!$allow_url_override || !isset($file_to_include))
    {
    	$file_to_include = "jxlrwtest.xls";
    }
    if(!$allow_url_override || !isset($max_rows))
    {
    	$max_rows = 0; //USE 0 for no max
    }
    if(!$allow_url_override || !isset($max_cols))
    {
    	$max_cols = 5; //USE 0 for no max
    }
    if(!$allow_url_override || !isset($debug))
    {
    	$debug = 0;  //1 for on 0 for off
    }
    if(!$allow_url_override || !isset($force_nobr))
    {
    	$force_nobr = 1;  //Force the info in cells not to wrap unless stated explicitly (newline)
    }
     
    require_once 'Excel/reader.php';
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding('CPa25a');
    $data->read($file_to_include);
    error_reporting(E_ALL ^ E_NOTICE);
    echo "
    <STYLE>
    .table_data
    {
    	border-style:ridge;
    	border-width:1;
    }
    .tab_base
    {
    	background:#C5D0DD;
    	font-weight:bold;
    	border-style:ridge;
    	border-width:1;
    	cursor:pointer;
    }
    .table_sub_heading
    {
    	background:#CCCCCC;
    	font-weight:bold;
    	border-style:ridge;
    	border-width:1;
    }
    .table_body
    {
    	background:#F0F0F0;
    	font-wieght:normal;
    	font-size:12;
    	font-family:sans-serif;
    	border-style:ridge;
    	border-width:1;
    	border-spacing: 0px;
    	border-collapse: collapse;
    }
    .tab_loaded
    {
    	background:#222222;
    	color:white;
    	font-weight:bold;
    	border-style:groove;
    	border-width:1;
    	cursor:pointer;
    }
    </STYLE>
    ";
    function make_alpha_from_numbers($number)
    {
    	$numeric = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	if($number<strlen($numeric))
    	{
    		return $numeric[$number];
    	}
    	else
    	{
    		$dev_by = floor($number/strlen($numeric));
    		return "" . make_alpha_from_numbers($dev_by-1) . make_alpha_from_numbers($number-($dev_by*strlen($numeric)));
    	}
    }
    echo "<SCRIPT LANGUAGE='JAVASCRIPT'>
    var sheet_HTML = Array();\n";
    for($sheet=0;$sheet<count($data->sheets);$sheet++)
    {
    	$table_output[$sheet] .= "<TABLE CLASS='table_body'>
    	<TR>
    		<TD>&nbsp;</TD>";
    	for($i=0;$i<$data->sheets[$sheet]['numCols']&&($i<=$max_cols||$max_cols==0);$i++)
    	{
    		$table_output[$sheet] .= "<TD CLASS='table_sub_heading' ALIGN=CENTER>" . make_alpha_from_numbers($i) . "</TD>";
    	}
    	for($row=1;$row<=$data->sheets[$sheet]['numRows']&&($row<=$max_rows||$max_rows==0);$row++)
    	{
    		$table_output[$sheet] .= "<TR><TD CLASS='table_sub_heading'>" . $row . "</TD>";
    		for($col=1;$col<=$data->sheets[$sheet]['numCols']&&($col<=$max_cols||$max_cols==0);$col++)
    		{
    			if($data->sheets[$sheet]['cellsInfo'][$row][$col]['colspan'] >=1 && $data->sheets[$sheet]['cellsInfo'][$row][$col]['rowspan'] >=1)
    			{
    				$this_cell_colspan = " COLSPAN=" . $data->sheets[$sheet]['cellsInfo'][$row][$col]['colspan'];
    				$this_cell_rowspan = " ROWSPAN=" . $data->sheets[$sheet]['cellsInfo'][$row][$col]['rowspan'];
    				for($i=1;$i<$data->sheets[$sheet]['cellsInfo'][$row][$col]['colspan'];$i++)
    				{
    					$data->sheets[$sheet]['cellsInfo'][$row][$col+$i]['dontprint']=1;
    				}
    				for($i=1;$i<$data->sheets[$sheet]['cellsInfo'][$row][$col]['rowspan'];$i++)
    				{
    					for($j=0;$j<$data->sheets[$sheet]['cellsInfo'][$row][$col]['colspan'];$j++)
    					{
    						$data->sheets[$sheet]['cellsInfo'][$row+$i][$col+$j]['dontprint']=1;
    					}
    				}
    			}
    			else if($data->sheets[$sheet]['cellsInfo'][$row][$col]['colspan'] >=1)
    			{
    				$this_cell_colspan = " COLSPAN=" . $data->sheets[$sheet]['cellsInfo'][$row][$col]['colspan'];
    				$this_cell_rowspan = "";
    				for($i=1;$i<$data->sheets[$sheet]['cellsInfo'][$row][$col]['colspan'];$i++)
    				{
    					$data->sheets[$sheet]['cellsInfo'][$row][$col+$i]['dontprint']=1;
    				}
    			}
    			else if($data->sheets[$sheet]['cellsInfo'][$row][$col]['rowspan'] >=1)
    			{
    				$this_cell_colspan = "";
    				$this_cell_rowspan = " ROWSPAN=" . $data->sheets[$sheet]['cellsInfo'][$row][$col]['rowspan'];
    				for($i=1;$i<$data->sheets[$sheet]['cellsInfo'][$row][$col]['rowspan'];$i++)
    				{
    					$data->sheets[$sheet]['cellsInfo'][$row+$i][$col]['dontprint']=1;
    				}
    			}
    			else
    			{
    				$this_cell_colspan = "";
    				$this_cell_rowspan = "";
    			}
    			if(!($data->sheets[$sheet]['cellsInfo'][$row][$col]['dontprint']))
    			{
    				$table_output[$sheet] .= "<TD CLASS='table_data' $this_cell_colspan $this_cell_rowspan>&nbsp;";
    				if($force_nobr)
    				{
    					$table_output[$sheet] .= "<NOBR>";
    				}
    				$table_output[$sheet] .= nl2br(htmlentities($data->sheets[$sheet]['cells'][$row][$col]));
    				if($force_nobr)
    				{
    					$table_output[$sheet] .= "</NOBR>";
    				}
    				$table_output[$sheet] .= "</TD>";
    			}
    		}
    		$table_output[$sheet] .= "</TR>";
    	}
    	$table_output[$sheet] .= "</TABLE>";
    	$table_output[$sheet] = str_replace("\n","",$table_output[$sheet]);
    	$table_output[$sheet] = str_replace("\r","",$table_output[$sheet]);
    	$table_output[$sheet] = str_replace("\t"," ",$table_output[$sheet]);
    	if($debug)
    	{
    		$debug_output = print_r($data->sheets[$sheet],true);
    		$debug_output = str_replace("\n","\\n",$debug_output);
    		$debug_output = str_replace("\r","\\r",$debug_output);
    		$table_output[$sheet] .= "<PRE>$debug_output</PRE>";
    	}
    	echo "sheet_HTML[$sheet] = \"$table_output[$sheet]\";\n";
    }
    echo "
    function change_tabs(sheet)
    {
    	//alert('sheet_tab_' + sheet);
    	for(i=0;i<" , count($data->sheets) , ";i++)
    	{
    		document.getElementById('sheet_tab_' + i).className = 'tab_base';
    	}
    	document.getElementById('table_loader_div').innerHTML=sheet_HTML[sheet];
    	document.getElementById('sheet_tab_' + sheet).className = 'tab_loaded';
     
    }
    </SCRIPT>";
    echo "
    <TABLE CLASS='table_body' NAME='tab_table'>
    <TR>";
    for($sheet=0;$sheet<count($data->sheets);$sheet++)
    {
    	echo "<TD CLASS='tab_base' ID='sheet_tab_$sheet' ALIGN=CENTER
    		ONMOUSEDOWN=\"change_tabs($sheet);\">", $data->boundsheets[$sheet]['name'] , "</TD>";
    }
     
    echo 
    "<TR>";
    echo "</TABLE>
    <DIV ID=table_loader_div></DIV>
    <SCRIPT LANGUAGE='JavaScript'>
    change_tabs(0);
    </SCRIPT>";
    //echo "<IFRAME NAME=table_loader_iframe SRC='about:blank' WIDTH=100 HEIGHT=100></IFRAME>";
    /*
    echo "<PRE>";
    print_r($data);
    echo "</PRE>";
    */
     
        endif;
    }

  2. #2
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 506
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 506
    Par défaut
    Regarde de ce côté PHPExcel

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débutant] Affichage fichier excel dans Webbrowser qui ne fonctionne pas.
    Par botbot dans le forum VB.NET
    Réponses: 3
    Dernier message: 16/04/2013, 23h04
  2. Problème d'affichage fichier Excel sur l'Explorateur
    Par jospinkapwa dans le forum Langage
    Réponses: 3
    Dernier message: 29/11/2011, 19h46
  3. [Toutes versions] Affichage fichiers Excel sur 2 écrans
    Par djip136 dans le forum Excel
    Réponses: 2
    Dernier message: 12/10/2010, 13h36
  4. Affichage Fenetre Parcourir (choix de fichier) Excel VBA
    Par AngeKenny dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 10/08/2006, 13h22
  5. [Servlet]POI et affichage d'un fichier excel dans IE
    Par vseb99 dans le forum Servlets/JSP
    Réponses: 3
    Dernier message: 08/02/2006, 14h59

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