Yii:: Read Excel File xlsx Format

Posted: July 4, 2011 in Php, Yii Framework

Php & Yii :: Read Excel File xlsx Format

The basic is from here http://www.yiiframework.com/extension/phpexcel-codeplex/

 

Installation

To read the excel xlsx format:

            Yii::import('application.vendors.PHPExcel',true);
            $objReader = PHPExcel_IOFactory::createReader('Excel2007');
            $objPHPExcel = $objReader->load($file); //$file --> your filepath and filename

            $objWorksheet = $objPHPExcel->getActiveSheet();
            $highestRow = $objWorksheet->getHighestRow(); // e.g. 10
            $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'
            $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5
            echo '<table>' . "\n";
            for ($row = 2; $row <= $highestRow; ++$row) {
              echo '<tr>' . "\n";
              for ($col = 0; $col <= $highestColumnIndex; ++$col) {
                echo '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>' . "\n";
              }
              echo '</tr>' . "\n";
            }
            echo '</table>' . "\n";
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s