New examples of Reading Workbooks
git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@62184 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
parent
b0fd47beee
commit
6b54d5a103
|
@ -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>
|
Binary file not shown.
Loading…
Reference in New Issue