PHP: Microsoft Excell Dosya Okuma Sınıfı (class.oleread.php)

PHP dili farklı formatlı dosya ve veri türlerine işleyebilmektedir. Bu yazıda Microsft Excel dosyasının içeriğini okuyan Oleread PHP sınıfını inceleyeceğiz.

PHP Excel

Görseldeki gibi demo.xls dosyasında yazılan verileri PHP ile okuyacağız.

Uygulama için örnek bir index.php dosyası yazalım.


<?php
// Sınıfı dosyaya dahil ediyoruz.
require_once 'Excel/reader.php';

// Cekilen Sınıftan bir <strong>Spreadsheet_Excel_Reader</strong> nesnesi oluşturuyoruz.
$data = new Spreadsheet_Excel_Reader();

// Set output Encoding.
$data->setOutputEncoding('CP1251');

$data->read('demo.xls');

/*
 $data->sheets[0]['numRows'] - count rows
 $data->sheets[0]['numCols'] - count columns
 $data->sheets[0]['cells'][$i][$j] - data from $i-row $j-column

 $data->sheets[0]['cellsInfo'][$i][$j] - extended info about cell

 $data->sheets[0]['cellsInfo'][$i][$j]['type'] = "date" | "number" | "unknown"
 if 'type' == "unknown" - use 'raw' value, because  cell contain value with format '0.00';
 $data->sheets[0]['cellsInfo'][$i][$j]['raw'] = value if cell without format
 $data->sheets[0]['cellsInfo'][$i][$j]['colspan']
 $data->sheets[0]['cellsInfo'][$i][$j]['rowspan']
*/

$satir=$data->sheets[0]['numRows']; //satir sayisi
$sutun=$data->sheets[0]['numCols'];//sutun sayisi

echo "<b>Satır sayısı: ".$satir;

echo "<br>Sütun sayısı: ".$sutun ."</b>";
?>
<table border="1" width="100%" align="left">
<?php
for ($i = 1; $i <= $satir; $i++) {
?>
<tr>
 <?php
 for ($j = 1; $j <= $sutun; $j++) {
 ?>
 <td><?=$data->sheets[0]['cells'][$i][$j]?></td>
 <?php

 }
 ?>
</tr>
<?php
}
?>
</table>

Uygulamanın çalışır demosunu incelemek için tıklayınız.

Uygulama dosyalarını zip şeklinde indirmek için tıklayınız.

Atilla Akoğlu

Creating web applications since 2004. e-commerce, entrepreneur and enterprise advisor. Always open for new projects, ideas and deals...  

Website - Twitter - Facebook - More Posts

5 Comments

  • 21 Şubat 2010 - 00:27 | Permalink

    mükemmel.nerde kullancam bilmiyorum ama yapıp uygulaması insanı mutlu ediyor :)

  • 22 Şubat 2010 - 13:10 | Permalink

    şimdilik biyerde kullanmayabilirsin muhammed, elbet bi işin düşer, bu yolla farklı bir uygulama yapman gerekebilir.

  • Musa Ulker
    25 Şubat 2010 - 09:25 | Permalink

    Bunu da incelemenizi öneririm;
    http://www.codeplex.com/PHPExcel

  • 16 Haziran 2011 - 11:05 | Permalink

    Ne yazık ki php 5.3.x ile çalıştıramadım.

  • 16 Kasım 2011 - 02:07 | Permalink

    malesef hata verdi neden olabilir?

    Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\excel\Excel\reader.php on line 504

  • Bir Cevap Yazın

    E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

    *

    Şu HTML etiketlerini ve özelliklerini kullanabilirsiniz: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>