mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-11-06 03:35:52 +00:00
committed by
Adrien Crivelli
parent
77199c9877
commit
07455d24f6
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -16,14 +18,14 @@ date_default_timezone_set('Europe/London');
|
||||
<body>
|
||||
|
||||
<h1>PhpSpreadsheet Reader Example #01</h1>
|
||||
<h2>Simple File Reader using \PhpOffice\PhpSpreadsheet\IOFactory::load()</h2>
|
||||
<h2>Simple File Reader using IOFactory::load()</h2>
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
|
||||
$spreadsheet = IOFactory::load($inputFileName);
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -24,7 +26,7 @@ require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using \PhpOffice\PhpSpreadsheet\Reader\Xls<br />';
|
||||
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
||||
$reader = new Xls();
|
||||
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xml();
|
||||
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Ods();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -16,7 +18,7 @@ date_default_timezone_set('Europe/London');
|
||||
<body>
|
||||
|
||||
<h1>PhpSpreadsheet Reader Example #03</h1>
|
||||
<h2>Simple File Reader using the \PhpOffice\PhpSpreadsheet\IOFactory to Return a Reader</h2>
|
||||
<h2>Simple File Reader using the IOFactory to Return a Reader</h2>
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||
@@ -31,7 +33,7 @@ $inputFileType = 'Xls';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
$spreadsheet = $reader->load($inputFileName);
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -16,18 +18,18 @@ date_default_timezone_set('Europe/London');
|
||||
<body>
|
||||
|
||||
<h1>PhpSpreadsheet Reader Example #04</h1>
|
||||
<h2>Simple File Reader using the \PhpOffice\PhpSpreadsheet\IOFactory to Identify a Reader to Use</h2>
|
||||
<h2>Simple File Reader using the IOFactory to Identify a Reader to Use</h2>
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
|
||||
$inputFileType = 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 />';
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
$spreadsheet = $reader->load($inputFileName);
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -29,7 +31,7 @@ $inputFileType = 'Xls';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
echo 'Turning Formatting off for Load<br />';
|
||||
$reader->setReadDataOnly(true);
|
||||
$spreadsheet = $reader->load($inputFileName);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -29,7 +31,7 @@ $inputFileType = 'Xls';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
echo 'Loading all WorkSheets<br />';
|
||||
$reader->setLoadAllSheets();
|
||||
$spreadsheet = $reader->load($inputFileName);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -30,7 +32,7 @@ $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 />';
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||
$reader->setLoadSheetsOnly($sheetname);
|
||||
$spreadsheet = $reader->load($inputFileName);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -30,7 +32,7 @@ $inputFileName = './sampleData/example1.xls';
|
||||
$sheetnames = ['Data Sheet #1', 'Data Sheet #3'];
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "', $sheetnames),'" only<br />';
|
||||
$reader->setLoadSheetsOnly($sheetnames);
|
||||
$spreadsheet = $reader->load($inputFileName);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -29,7 +32,7 @@ $inputFileType = 'Xls';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
$sheetname = 'Data Sheet #3';
|
||||
|
||||
class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
class MyReadFilter implements IReadFilter
|
||||
{
|
||||
public function readCell($column, $row, $worksheetName = '')
|
||||
{
|
||||
@@ -47,7 +50,7 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
$filterSubset = new MyReadFilter();
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||
$reader->setLoadSheetsOnly($sheetname);
|
||||
echo 'Loading Sheet using filter<br />';
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -29,7 +32,7 @@ $inputFileType = 'Xls';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
$sheetname = 'Data Sheet #3';
|
||||
|
||||
class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
class MyReadFilter implements IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
@@ -59,7 +62,7 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
$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 />';
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||
$reader->setLoadSheetsOnly($sheetname);
|
||||
echo 'Loading Sheet using configurable filter<br />';
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -28,8 +31,8 @@ $inputFileType = 'Xls';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example2.xls';
|
||||
|
||||
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */
|
||||
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
/** Define a Read Filter class implementing IReadFilter */
|
||||
class chunkReadFilter implements IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
@@ -60,7 +63,7 @@ class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
|
||||
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 **/
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -28,8 +31,8 @@ $inputFileType = 'Xls';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example2.xls';
|
||||
|
||||
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */
|
||||
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
/** Define a Read Filter class implementing IReadFilter */
|
||||
class chunkReadFilter implements IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
@@ -60,7 +63,7 @@ class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
|
||||
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 **/
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -24,7 +26,7 @@ require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||
$inputFileType = 'Csv';
|
||||
$inputFileNames = ['./sampleData/example1.csv', './sampleData/example2.csv'];
|
||||
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = 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 />';
|
||||
$spreadsheet = $reader->load($inputFileName);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -24,8 +28,8 @@ require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||
$inputFileType = 'Csv';
|
||||
$inputFileName = './sampleData/example2.csv';
|
||||
|
||||
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */
|
||||
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
/** Define a Read Filter class implementing IReadFilter */
|
||||
class chunkReadFilter implements IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
@@ -56,7 +60,7 @@ class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||
|
||||
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 **/
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
@@ -71,7 +75,7 @@ $reader->setReadFilter($chunkFilter)
|
||||
->setContiguous(true);
|
||||
|
||||
/* Instantiate a new PhpSpreadsheet object manually **/
|
||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
||||
$spreadsheet = new Spreadsheet();
|
||||
|
||||
/* Set a sheet index **/
|
||||
$sheet = 0;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Cell;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -21,12 +24,12 @@ date_default_timezone_set('Europe/London');
|
||||
|
||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||
|
||||
\PhpOffice\PhpSpreadsheet\Cell::setValueBinder(new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder());
|
||||
Cell::setValueBinder(new Cell\AdvancedValueBinder());
|
||||
|
||||
$inputFileType = 'Csv';
|
||||
$inputFileName = './sampleData/example1.tsv';
|
||||
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$reader->setDelimiter("\t");
|
||||
$spreadsheet = $reader->load($inputFileName);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use InvalidArgumentException;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -24,8 +27,8 @@ require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||
$inputFileName = './sampleData/example_1.xls';
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
|
||||
try {
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$spreadsheet = IOFactory::load($inputFileName);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -29,7 +31,7 @@ $inputFileType = 'Xls';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
|
||||
/* Read the list of Worksheet Names from the Workbook file **/
|
||||
echo 'Read the list of Worksheets in the WorkBook<br />';
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -30,7 +32,7 @@ $inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
$worksheetNames = $reader->listWorksheetNames($inputFileName);
|
||||
|
||||
echo '<h3>Worksheet Names</h3>';
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -30,7 +32,7 @@ $inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||
$reader = IOFactory::createReader($inputFileType);
|
||||
$worksheetData = $reader->listWorksheetInfo($inputFileName);
|
||||
|
||||
echo '<h3>Worksheet Information</h3>';
|
||||
|
||||
Reference in New Issue
Block a user