init
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #01</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #01</h1>
|
||||
<h2>Simple File Reader using PHPExcel_IOFactory::load()</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
|
||||
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #02</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #02</h1>
|
||||
<h2>Simple File Reader using a Specified Reader</h2>
|
||||
<?php
|
||||
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using PHPExcel_Reader_Excel5<br />';
|
||||
$objReader = new PHPExcel_Reader_Excel5();
|
||||
// $objReader = new PHPExcel_Reader_Excel2007();
|
||||
// $objReader = new PHPExcel_Reader_Excel2003XML();
|
||||
// $objReader = new PHPExcel_Reader_OOCalc();
|
||||
// $objReader = new PHPExcel_Reader_SYLK();
|
||||
// $objReader = new PHPExcel_Reader_Gnumeric();
|
||||
// $objReader = new PHPExcel_Reader_CSV();
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #03</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #03</h1>
|
||||
<h2>Simple File Reader using the PHPExcel_IOFactory to Return a Reader</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'SYLK';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
// $inputFileType = 'CSV';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #04</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #04</h1>
|
||||
<h2>Simple File Reader using the PHPExcel_IOFactory to Identify a Reader to Use</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
|
||||
echo 'File ',pathinfo($inputFileName,PATHINFO_BASENAME),' has been identified as an ',$inputFileType,' file<br />';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with the identified reader type<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #05</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #05</h1>
|
||||
<h2>Simple File Reader using the "Read Data Only" Option</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Turning Formatting off for Load<br />';
|
||||
$objReader->setReadDataOnly(true);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #06</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #06</h1>
|
||||
<h2>Simple File Reader Loading All WorkSheets</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading all WorkSheets<br />';
|
||||
$objReader->setLoadAllSheets();
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo $sheetIndex,' -> ',$loadedSheetName,'<br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #07</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #07</h1>
|
||||
<h2>Simple File Reader Loading a Single Named WorkSheet</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
$sheetname = 'Data Sheet #2';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||
$objReader->setLoadSheetsOnly($sheetname);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo $sheetIndex,' -> ',$loadedSheetName,'<br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #08</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #08</h1>
|
||||
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
$sheetnames = array('Data Sheet #1','Data Sheet #3');
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "',$sheetnames),'" only<br />';
|
||||
$objReader->setLoadSheetsOnly($sheetnames);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo $sheetIndex,' -> ',$loadedSheetName,'<br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #09</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #09</h1>
|
||||
<h2>Simple File Reader Using a Read Filter</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
$sheetname = 'Data Sheet #3';
|
||||
|
||||
|
||||
class MyReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
// Read rows 1 to 7 and columns A to E only
|
||||
if ($row >= 1 && $row <= 7) {
|
||||
if (in_array($column,range('A','E'))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$filterSubset = new MyReadFilter();
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||
$objReader->setLoadSheetsOnly($sheetname);
|
||||
echo 'Loading Sheet using filter<br />';
|
||||
$objReader->setReadFilter($filterSubset);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #10</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #10</h1>
|
||||
<h2>Simple File Reader Using a Configurable Read Filter</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
$sheetname = 'Data Sheet #3';
|
||||
|
||||
|
||||
class MyReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
private $_endRow = 0;
|
||||
|
||||
private $_columns = array();
|
||||
|
||||
public function __construct($startRow, $endRow, $columns) {
|
||||
$this->_startRow = $startRow;
|
||||
$this->_endRow = $endRow;
|
||||
$this->_columns = $columns;
|
||||
}
|
||||
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
if ($row >= $this->_startRow && $row <= $this->_endRow) {
|
||||
if (in_array($column,$this->_columns)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$filterSubset = new MyReadFilter(9,15,range('G','K'));
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||
$objReader->setLoadSheetsOnly($sheetname);
|
||||
echo 'Loading Sheet using configurable filter<br />';
|
||||
$objReader->setReadFilter($filterSubset);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #11</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #11</h1>
|
||||
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 1)</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example2.xls';
|
||||
|
||||
|
||||
/** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */
|
||||
class chunkReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
private $_endRow = 0;
|
||||
|
||||
/** We expect a list of the rows that we want to read to be passed into the constructor */
|
||||
public function __construct($startRow, $chunkSize) {
|
||||
$this->_startRow = $startRow;
|
||||
$this->_endRow = $startRow + $chunkSize;
|
||||
}
|
||||
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
// Only read the heading row, and the rows that were configured in the constructor
|
||||
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
/** Define how many rows we want for each "chunk" **/
|
||||
$chunkSize = 20;
|
||||
|
||||
/** Loop to read our worksheet in "chunk size" blocks **/
|
||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />';
|
||||
/** Create a new Instance of our Read Filter, passing in the limits on which rows we want to read **/
|
||||
$chunkFilter = new chunkReadFilter($startRow,$chunkSize);
|
||||
/** Tell the Reader that we want to use the new Read Filter that we've just Instantiated **/
|
||||
$objReader->setReadFilter($chunkFilter);
|
||||
/** Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
// Do some processing here
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br /><br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #12</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #12</h1>
|
||||
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)</h2>
|
||||
<?php
|
||||
|
||||
/** Set Include path to point at the PHPExcel Classes folder **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** Include PHPExcel_IOFactory **/
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example2.xls';
|
||||
|
||||
|
||||
/** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */
|
||||
class chunkReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
private $_endRow = 0;
|
||||
|
||||
/** Set the list of rows that we want to read */
|
||||
public function setRows($startRow, $chunkSize) {
|
||||
$this->_startRow = $startRow;
|
||||
$this->_endRow = $startRow + $chunkSize;
|
||||
}
|
||||
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
|
||||
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
/** Define how many rows we want to read for each "chunk" **/
|
||||
$chunkSize = 20;
|
||||
/** Create a new Instance of our Read Filter **/
|
||||
$chunkFilter = new chunkReadFilter();
|
||||
|
||||
/** Tell the Reader that we want to use the Read Filter that we've Instantiated **/
|
||||
$objReader->setReadFilter($chunkFilter);
|
||||
|
||||
/** Loop to read our worksheet in "chunk size" blocks **/
|
||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />';
|
||||
/** Tell the Read Filter, the limits on which rows we want to read this iteration **/
|
||||
$chunkFilter->setRows($startRow,$chunkSize);
|
||||
/** Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
// Do some processing here
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br /><br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #13</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #13</h1>
|
||||
<h2>Simple File Reader for Multiple CSV Files</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'CSV';
|
||||
$inputFileNames = array('./sampleData/example1.csv','./sampleData/example2.csv');
|
||||
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$inputFileName = array_shift($inputFileNames);
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
$objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
||||
foreach($inputFileNames as $sheet => $inputFileName) {
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' into WorkSheet #',($sheet+2),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader->setSheetIndex($sheet+1);
|
||||
$objReader->loadIntoExisting($inputFileName,$objPHPExcel);
|
||||
$objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
||||
}
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,'</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br /><br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #15</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #14</h1>
|
||||
<h2>Reading a Large CSV file in "Chunks" to split across multiple Worksheets</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'CSV';
|
||||
$inputFileName = './sampleData/example2.csv';
|
||||
|
||||
/** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */
|
||||
class chunkReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
private $_endRow = 0;
|
||||
|
||||
/** Set the list of rows that we want to read */
|
||||
public function setRows($startRow, $chunkSize) {
|
||||
$this->_startRow = $startRow;
|
||||
$this->_endRow = $startRow + $chunkSize;
|
||||
}
|
||||
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
|
||||
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
/** Define how many rows we want to read for each "chunk" **/
|
||||
$chunkSize = 100;
|
||||
/** Create a new Instance of our Read Filter **/
|
||||
$chunkFilter = new chunkReadFilter();
|
||||
|
||||
/** Tell the Reader that we want to use the Read Filter that we've Instantiated **/
|
||||
/** and that we want to store it in contiguous rows/columns **/
|
||||
$objReader->setReadFilter($chunkFilter)
|
||||
->setContiguous(true);
|
||||
|
||||
|
||||
/** Instantiate a new PHPExcel object manually **/
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
/** Set a sheet index **/
|
||||
$sheet = 0;
|
||||
/** Loop to read our worksheet in "chunk size" blocks **/
|
||||
/** $startRow is set to 2 initially because we always read the headings in row #1 **/
|
||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||
echo 'Loading WorkSheet #',($sheet+1),' using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />';
|
||||
/** Tell the Read Filter, the limits on which rows we want to read this iteration **/
|
||||
$chunkFilter->setRows($startRow,$chunkSize);
|
||||
|
||||
/** Increment the worksheet index pointer for the Reader **/
|
||||
$objReader->setSheetIndex($sheet);
|
||||
/** Load only the rows that match our filter into a new worksheet in the PHPExcel Object **/
|
||||
$objReader->loadIntoExisting($inputFileName,$objPHPExcel);
|
||||
/** Set the worksheet title (to reference the "sheet" of data that we've loaded) **/
|
||||
/** and increment the sheet index as well **/
|
||||
$objPHPExcel->getActiveSheet()->setTitle('Country Data #'.(++$sheet));
|
||||
}
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,'</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #15</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #15</h1>
|
||||
<h2>Simple File Reader for Tab-Separated Value File using the Advanced Value Binder</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );
|
||||
|
||||
|
||||
$inputFileType = 'CSV';
|
||||
$inputFileName = './sampleData/example1.tsv';
|
||||
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader->setDelimiter("\t");
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
$objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Formatted)</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Unformatted)</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,false,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Raw)</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #16</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #16</h1>
|
||||
<h2>Handling Loader Exceptions using Try/Catch</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileName = './sampleData/example_1.xls';
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
|
||||
try {
|
||||
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
|
||||
} catch(PHPExcel_Reader_Exception $e) {
|
||||
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #17</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #17</h1>
|
||||
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
|
||||
|
||||
/** Read the list of Worksheet Names from the Workbook file **/
|
||||
echo 'Read the list of Worksheets in the WorkBook<br />';
|
||||
$worksheetNames = $objReader->listWorksheetNames($inputFileName);
|
||||
|
||||
echo 'There are ',count($worksheetNames),' worksheet',((count($worksheetNames) == 1) ? '' : 's'),' in the workbook<br /><br />';
|
||||
foreach($worksheetNames as $worksheetName) {
|
||||
echo $worksheetName,'<br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #18</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #18</h1>
|
||||
<h2>Reading list of WorkSheets without loading entire file</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$worksheetNames = $objReader->listWorksheetNames($inputFileName);
|
||||
|
||||
echo '<h3>Worksheet Names</h3>';
|
||||
echo '<ol>';
|
||||
foreach ($worksheetNames as $worksheetName) {
|
||||
echo '<li>', $worksheetName, '</li>';
|
||||
}
|
||||
echo '</ol>';
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #19</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #19</h1>
|
||||
<h2>Reading WorkSheet information without loading entire file</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$worksheetData = $objReader->listWorksheetInfo($inputFileName);
|
||||
|
||||
echo '<h3>Worksheet Information</h3>';
|
||||
echo '<ol>';
|
||||
foreach ($worksheetData as $worksheet) {
|
||||
echo '<li>', $worksheet['worksheetName'], '<br />';
|
||||
echo 'Rows: ', $worksheet['totalRows'], ' Columns: ', $worksheet['totalColumns'], '<br />';
|
||||
echo 'Cell Range: A1:', $worksheet['lastColumnLetter'], $worksheet['totalRows'];
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ol>';
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user