Remove obsolete `$obj` prefix in cod sample
This commit is contained in:
parent
90da50f3c7
commit
17d1976526
|
@ -28,14 +28,14 @@ include 'PHPExcel/IOFactory.php';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using \PhpOffice\PhpSpreadsheet\Reader\Xls<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using \PhpOffice\PhpSpreadsheet\Reader\Xls<br />';
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\Excel2003XML();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Excel2003XML();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\Ods();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Ods();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\SYLK();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\SYLK();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\Gnumeric();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Gnumeric();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@ $inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
|
||||||
echo 'File ',pathinfo($inputFileName, PATHINFO_BASENAME),' has been identified as an ',$inputFileType,' file<br />';
|
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 />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with the identified reader type<br />';
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,10 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
echo 'Turning Formatting off for Load<br />';
|
echo 'Turning Formatting off for Load<br />';
|
||||||
$objReader->setReadDataOnly(true);
|
$reader->setReadDataOnly(true);
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,10 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
echo 'Loading all WorkSheets<br />';
|
echo 'Loading all WorkSheets<br />';
|
||||||
$objReader->setLoadAllSheets();
|
$reader->setLoadAllSheets();
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,10 @@ $inputFileName = './sampleData/example1.xls';
|
||||||
$sheetname = 'Data Sheet #2';
|
$sheetname = 'Data Sheet #2';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||||
$objReader->setLoadSheetsOnly($sheetname);
|
$reader->setLoadSheetsOnly($sheetname);
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,10 @@ $inputFileName = './sampleData/example1.xls';
|
||||||
$sheetnames = ['Data Sheet #1', 'Data Sheet #3'];
|
$sheetnames = ['Data Sheet #1', 'Data Sheet #3'];
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "', $sheetnames),'" only<br />';
|
echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "', $sheetnames),'" only<br />';
|
||||||
$objReader->setLoadSheetsOnly($sheetnames);
|
$reader->setLoadSheetsOnly($sheetnames);
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -51,12 +51,12 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||||
$filterSubset = new MyReadFilter();
|
$filterSubset = new MyReadFilter();
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||||
$objReader->setLoadSheetsOnly($sheetname);
|
$reader->setLoadSheetsOnly($sheetname);
|
||||||
echo 'Loading Sheet using filter<br />';
|
echo 'Loading Sheet using filter<br />';
|
||||||
$objReader->setReadFilter($filterSubset);
|
$reader->setReadFilter($filterSubset);
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,12 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||||
$filterSubset = new MyReadFilter(9, 15, range('G', 'K'));
|
$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 />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||||
$objReader->setLoadSheetsOnly($sheetname);
|
$reader->setLoadSheetsOnly($sheetname);
|
||||||
echo 'Loading Sheet using configurable filter<br />';
|
echo 'Loading Sheet using configurable filter<br />';
|
||||||
$objReader->setReadFilter($filterSubset);
|
$reader->setReadFilter($filterSubset);
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,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 />';
|
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 **/
|
/* Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
@ -72,9 +72,9 @@ for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||||
/* Create a new Instance of our Read Filter, passing in the limits on which rows we want to read **/
|
/* Create a new Instance of our Read Filter, passing in the limits on which rows we want to read **/
|
||||||
$chunkFilter = new chunkReadFilter($startRow, $chunkSize);
|
$chunkFilter = new chunkReadFilter($startRow, $chunkSize);
|
||||||
/* Tell the Reader that we want to use the new Read Filter that we've just Instantiated **/
|
/* Tell the Reader that we want to use the new Read Filter that we've just Instantiated **/
|
||||||
$objReader->setReadFilter($chunkFilter);
|
$reader->setReadFilter($chunkFilter);
|
||||||
/* Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/
|
/* Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
// Do some processing here
|
// Do some processing here
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,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 />';
|
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 **/
|
/* Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ $chunkSize = 20;
|
||||||
$chunkFilter = new chunkReadFilter();
|
$chunkFilter = new chunkReadFilter();
|
||||||
|
|
||||||
/* Tell the Reader that we want to use the Read Filter that we've Instantiated **/
|
/* Tell the Reader that we want to use the Read Filter that we've Instantiated **/
|
||||||
$objReader->setReadFilter($chunkFilter);
|
$reader->setReadFilter($chunkFilter);
|
||||||
|
|
||||||
/* Loop to read our worksheet in "chunk size" blocks **/
|
/* Loop to read our worksheet in "chunk size" blocks **/
|
||||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||||
|
@ -77,7 +77,7 @@ for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||||
/* Tell the Read Filter, the limits on which rows we want to read this iteration **/
|
/* Tell the Read Filter, the limits on which rows we want to read this iteration **/
|
||||||
$chunkFilter->setRows($startRow, $chunkSize);
|
$chunkFilter->setRows($startRow, $chunkSize);
|
||||||
/* Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/
|
/* Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
// Do some processing here
|
// Do some processing here
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,15 @@ include 'PHPExcel/IOFactory.php';
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
$inputFileNames = ['./sampleData/example1.csv', './sampleData/example2.csv'];
|
$inputFileNames = ['./sampleData/example1.csv', './sampleData/example2.csv'];
|
||||||
|
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
$inputFileName = array_shift($inputFileNames);
|
$inputFileName = array_shift($inputFileNames);
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
||||||
foreach ($inputFileNames as $sheet => $inputFileName) {
|
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 />';
|
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);
|
$reader->setSheetIndex($sheet + 1);
|
||||||
$objReader->loadIntoExisting($inputFileName, $spreadsheet);
|
$reader->loadIntoExisting($inputFileName, $spreadsheet);
|
||||||
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,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 />';
|
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 **/
|
/* Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ $chunkFilter = new chunkReadFilter();
|
||||||
|
|
||||||
/* Tell the Reader that we want to use the Read Filter that we've Instantiated **/
|
/* 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 **/
|
/* and that we want to store it in contiguous rows/columns **/
|
||||||
$objReader->setReadFilter($chunkFilter)
|
$reader->setReadFilter($chunkFilter)
|
||||||
->setContiguous(true);
|
->setContiguous(true);
|
||||||
|
|
||||||
/* Instantiate a new PHPExcel object manually **/
|
/* Instantiate a new PHPExcel object manually **/
|
||||||
|
@ -77,9 +77,9 @@ for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||||
$chunkFilter->setRows($startRow, $chunkSize);
|
$chunkFilter->setRows($startRow, $chunkSize);
|
||||||
|
|
||||||
/* Increment the worksheet index pointer for the Reader **/
|
/* Increment the worksheet index pointer for the Reader **/
|
||||||
$objReader->setSheetIndex($sheet);
|
$reader->setSheetIndex($sheet);
|
||||||
/* Load only the rows that match our filter into a new worksheet in the PHPExcel Object **/
|
/* Load only the rows that match our filter into a new worksheet in the PHPExcel Object **/
|
||||||
$objReader->loadIntoExisting($inputFileName, $spreadsheet);
|
$reader->loadIntoExisting($inputFileName, $spreadsheet);
|
||||||
/* Set the worksheet title (to reference the "sheet" of data that we've loaded) **/
|
/* Set the worksheet title (to reference the "sheet" of data that we've loaded) **/
|
||||||
/* and increment the sheet index as well **/
|
/* and increment the sheet index as well **/
|
||||||
$spreadsheet->getActiveSheet()->setTitle('Country Data #' . (++$sheet));
|
$spreadsheet->getActiveSheet()->setTitle('Country Data #' . (++$sheet));
|
||||||
|
|
|
@ -25,10 +25,10 @@ include 'PHPExcel/IOFactory.php';
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
$inputFileName = './sampleData/example1.tsv';
|
$inputFileName = './sampleData/example1.tsv';
|
||||||
|
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$objReader->setDelimiter("\t");
|
$reader->setDelimiter("\t");
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
|
@ -33,11 +33,11 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
/* Read the list of Worksheet Names from the Workbook file **/
|
/* Read the list of Worksheet Names from the Workbook file **/
|
||||||
echo 'Read the list of Worksheets in the WorkBook<br />';
|
echo 'Read the list of Worksheets in the WorkBook<br />';
|
||||||
$worksheetNames = $objReader->listWorksheetNames($inputFileName);
|
$worksheetNames = $reader->listWorksheetNames($inputFileName);
|
||||||
|
|
||||||
echo 'There are ',count($worksheetNames),' worksheet',((count($worksheetNames) == 1) ? '' : 's'),' in the workbook<br /><br />';
|
echo 'There are ',count($worksheetNames),' worksheet',((count($worksheetNames) == 1) ? '' : 's'),' in the workbook<br /><br />';
|
||||||
foreach ($worksheetNames as $worksheetName) {
|
foreach ($worksheetNames as $worksheetName) {
|
||||||
|
|
|
@ -34,8 +34,8 @@ $inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
|
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
$worksheetNames = $objReader->listWorksheetNames($inputFileName);
|
$worksheetNames = $reader->listWorksheetNames($inputFileName);
|
||||||
|
|
||||||
echo '<h3>Worksheet Names</h3>';
|
echo '<h3>Worksheet Names</h3>';
|
||||||
echo '<ol>';
|
echo '<ol>';
|
||||||
|
|
|
@ -34,8 +34,8 @@ $inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||||
|
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
$worksheetData = $objReader->listWorksheetInfo($inputFileName);
|
$worksheetData = $reader->listWorksheetInfo($inputFileName);
|
||||||
|
|
||||||
echo '<h3>Worksheet Information</h3>';
|
echo '<h3>Worksheet Information</h3>';
|
||||||
echo '<ol>';
|
echo '<ol>';
|
||||||
|
|
|
@ -29,9 +29,9 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
/* Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/* Load $inputFileName to a PHPExcel Object **/
|
/* Load $inputFileName to a PHPExcel Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ $inputFileType = 'Xlsx';
|
||||||
$inputFileName = './sampleData/example1.xlsx';
|
$inputFileName = './sampleData/example1.xlsx';
|
||||||
|
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
/* Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/* Load $inputFileName to a PHPExcel Object **/
|
/* Load $inputFileName to a PHPExcel Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ $inputFileType = 'Xlsx';
|
||||||
$inputFileName = './sampleData/example1.xlsx';
|
$inputFileName = './sampleData/example1.xlsx';
|
||||||
|
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
/* Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/* Load $inputFileName to a PHPExcel Object **/
|
/* Load $inputFileName to a PHPExcel Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example2.xls';
|
$inputFileName = './sampleData/example2.xls';
|
||||||
|
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
/* Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/* Load $inputFileName to a PHPExcel Object **/
|
/* Load $inputFileName to a PHPExcel Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
|
|
||||||
|
|
278
docs/index.md
278
docs/index.md
|
@ -243,16 +243,16 @@ If you don't specify an index position as the second argument, then the new work
|
||||||
Sheets within the same workbook can be copied by creating a clone of the worksheet you wish to copy, and then using the addSheet() method to insert the clone into the workbook.
|
Sheets within the same workbook can be copied by creating a clone of the worksheet you wish to copy, and then using the addSheet() method to insert the clone into the workbook.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objClonedWorksheet = clone $spreadsheet->getSheetByName('Worksheet 1');
|
$clonedWorksheet = clone $spreadsheet->getSheetByName('Worksheet 1');
|
||||||
$objClonedWorksheet->setTitle('Copy of Worksheet 1')
|
$clonedWorksheet->setTitle('Copy of Worksheet 1')
|
||||||
$spreadsheet->addSheet($objClonedWorksheet);
|
$spreadsheet->addSheet($clonedWorksheet);
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also copy worksheets from one workbook to another, though this is more complex as PhpSpreadsheet also has to replicate the styling between the two workbooks. The addExternalSheet() method is provided for this purpose.
|
You can also copy worksheets from one workbook to another, though this is more complex as PhpSpreadsheet also has to replicate the styling between the two workbooks. The addExternalSheet() method is provided for this purpose.
|
||||||
|
|
||||||
```
|
```
|
||||||
$objClonedWorksheet = clone $spreadsheet1->getSheetByName('Worksheet 1');
|
$clonedWorksheet = clone $spreadsheet1->getSheetByName('Worksheet 1');
|
||||||
$spreadsheet->addExternalSheet($objClonedWorksheet);
|
$spreadsheet->addExternalSheet($clonedWorksheet);
|
||||||
```
|
```
|
||||||
|
|
||||||
In both cases, it is the developer's responsibility to ensure that worksheet names are not duplicated. PhpSpreadsheet will throw an exception if you attempt to copy worksheets that will result in a duplicate name.
|
In both cases, it is the developer's responsibility to ensure that worksheet names are not duplicated. PhpSpreadsheet will throw an exception if you attempt to copy worksheets that will result in a duplicate name.
|
||||||
|
@ -536,14 +536,14 @@ The easiest way to loop cells is by using iterators. Using iterators, one can us
|
||||||
Below is an example where we read all the values in a worksheet and display them in a table.
|
Below is an example where we read all the values in a worksheet and display them in a table.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
||||||
$objReader->setReadDataOnly(TRUE);
|
$reader->setReadDataOnly(TRUE);
|
||||||
$spreadsheet = $objReader->load("test.xlsx");
|
$spreadsheet = $reader->load("test.xlsx");
|
||||||
|
|
||||||
$objWorksheet = $spreadsheet->getActiveSheet();
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
echo '<table>' . PHP_EOL;
|
echo '<table>' . PHP_EOL;
|
||||||
foreach ($objWorksheet->getRowIterator() as $row) {
|
foreach ($worksheet->getRowIterator() as $row) {
|
||||||
echo '<tr>' . PHP_EOL;
|
echo '<tr>' . PHP_EOL;
|
||||||
$cellIterator = $row->getCellIterator();
|
$cellIterator = $row->getCellIterator();
|
||||||
$cellIterator->setIterateOnlyExistingCells(FALSE); // This loops through all cells,
|
$cellIterator->setIterateOnlyExistingCells(FALSE); // This loops through all cells,
|
||||||
|
@ -574,14 +574,14 @@ Note: In PhpSpreadsheet column index is 0-based while row index is 1-based. That
|
||||||
Below is an example where we read all the values in a worksheet and display them in a table.
|
Below is an example where we read all the values in a worksheet and display them in a table.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
||||||
$objReader->setReadDataOnly(TRUE);
|
$reader->setReadDataOnly(TRUE);
|
||||||
$spreadsheet = $objReader->load("test.xlsx");
|
$spreadsheet = $reader->load("test.xlsx");
|
||||||
|
|
||||||
$objWorksheet = $spreadsheet->getActiveSheet();
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
// Get the highest row and column numbers referenced in the worksheet
|
// Get the highest row and column numbers referenced in the worksheet
|
||||||
$highestRow = $objWorksheet->getHighestRow(); // e.g. 10
|
$highestRow = $worksheet->getHighestRow(); // e.g. 10
|
||||||
$highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'
|
$highestColumn = $worksheet->getHighestColumn(); // e.g 'F'
|
||||||
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($highestColumn); // e.g. 5
|
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell::columnIndexFromString($highestColumn); // e.g. 5
|
||||||
|
|
||||||
echo '<table>' . "\n";
|
echo '<table>' . "\n";
|
||||||
|
@ -589,7 +589,7 @@ for ($row = 1; $row <= $highestRow; ++$row) {
|
||||||
echo '<tr>' . PHP_EOL;
|
echo '<tr>' . PHP_EOL;
|
||||||
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
|
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
|
||||||
echo '<td>' .
|
echo '<td>' .
|
||||||
$objWorksheet->getCellByColumnAndRow($col, $row)
|
$worksheet->getCellByColumnAndRow($col, $row)
|
||||||
->getValue() .
|
->getValue() .
|
||||||
'</td>' . PHP_EOL;
|
'</td>' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
@ -601,14 +601,14 @@ echo '</table>' . PHP_EOL;
|
||||||
Alternatively, you can take advantage of PHP's "Perl-style" character incrementors to loop through the cells by coordinate:
|
Alternatively, you can take advantage of PHP's "Perl-style" character incrementors to loop through the cells by coordinate:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
||||||
$objReader->setReadDataOnly(TRUE);
|
$reader->setReadDataOnly(TRUE);
|
||||||
$spreadsheet = $objReader->load("test.xlsx");
|
$spreadsheet = $reader->load("test.xlsx");
|
||||||
|
|
||||||
$objWorksheet = $spreadsheet->getActiveSheet();
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
// Get the highest row number and column letter referenced in the worksheet
|
// Get the highest row number and column letter referenced in the worksheet
|
||||||
$highestRow = $objWorksheet->getHighestRow(); // e.g. 10
|
$highestRow = $worksheet->getHighestRow(); // e.g. 10
|
||||||
$highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'
|
$highestColumn = $worksheet->getHighestColumn(); // e.g 'F'
|
||||||
// Increment the highest column letter
|
// Increment the highest column letter
|
||||||
$highestColumn++;
|
$highestColumn++;
|
||||||
|
|
||||||
|
@ -617,7 +617,7 @@ for ($row = 1; $row <= $highestRow; ++$row) {
|
||||||
echo '<tr>' . PHP_EOL;
|
echo '<tr>' . PHP_EOL;
|
||||||
for ($col = 'A'; $col != $highestColumn; ++$col) {
|
for ($col = 'A'; $col != $highestColumn; ++$col) {
|
||||||
echo '<td>' .
|
echo '<td>' .
|
||||||
$objWorksheet->getCell($col . $row)
|
$worksheet->getCell($col . $row)
|
||||||
->getValue() .
|
->getValue() .
|
||||||
'</td>' . PHP_EOL;
|
'</td>' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
@ -685,16 +685,16 @@ A typical use of this feature is when you need to read files uploaded by your us
|
||||||
If you need to set some properties on the reader, (e.g. to only read data, see more about this later), then you may instead want to use this variant:
|
If you need to set some properties on the reader, (e.g. to only read data, see more about this later), then you may instead want to use this variant:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile("05featuredemo.xlsx");
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile("05featuredemo.xlsx");
|
||||||
$objReader->setReadDataOnly(true);
|
$reader->setReadDataOnly(true);
|
||||||
$objReader->load("05featuredemo.xlsx");
|
$reader->load("05featuredemo.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
You can create a \PhpOffice\PhpSpreadsheet\Reader\IReader instance using \PhpOffice\PhpSpreadsheet\IOFactory in explicit mode using the following code sample:
|
You can create a \PhpOffice\PhpSpreadsheet\Reader\IReader instance using \PhpOffice\PhpSpreadsheet\IOFactory in explicit mode using the following code sample:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
|
||||||
$spreadsheet = $objReader->load("05featuredemo.xlsx");
|
$spreadsheet = $reader->load("05featuredemo.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that automatic type resolving mode is slightly slower than explicit mode.
|
Note that automatic type resolving mode is slightly slower than explicit mode.
|
||||||
|
@ -704,8 +704,8 @@ Note that automatic type resolving mode is slightly slower than explicit mode.
|
||||||
You can create a PhpOffice\PhpSpreadsheet\Writer\IWriter instance using \PhpOffice\PhpSpreadsheet\IOFactory:
|
You can create a PhpOffice\PhpSpreadsheet\Writer\IWriter instance using \PhpOffice\PhpSpreadsheet\IOFactory:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, "Xlsx");
|
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, "Xlsx");
|
||||||
$objWriter->save("05featuredemo.xlsx");
|
$writer->save("05featuredemo.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
## Excel 2007 (SpreadsheetML) file format
|
## Excel 2007 (SpreadsheetML) file format
|
||||||
|
@ -719,8 +719,8 @@ Xlsx file format is the main file format of PhpSpreadsheet. It allows outputting
|
||||||
You can read an .xlsx file using the following code:
|
You can read an .xlsx file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
$spreadsheet = $objReader->load("05featuredemo.xlsx");
|
$spreadsheet = $reader->load("05featuredemo.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read data only
|
#### Read data only
|
||||||
|
@ -728,9 +728,9 @@ $spreadsheet = $objReader->load("05featuredemo.xlsx");
|
||||||
You can set the option setReadDataOnly on the reader, to instruct the reader to ignore styling, data validation, … and just read cell data:
|
You can set the option setReadDataOnly on the reader, to instruct the reader to ignore styling, data validation, … and just read cell data:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
$objReader->setReadDataOnly(true);
|
$reader->setReadDataOnly(true);
|
||||||
$spreadsheet = $objReader->load("05featuredemo.xlsx");
|
$spreadsheet = $reader->load("05featuredemo.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read specific sheets only
|
#### Read specific sheets only
|
||||||
|
@ -738,9 +738,9 @@ $spreadsheet = $objReader->load("05featuredemo.xlsx");
|
||||||
You can set the option setLoadSheetsOnly on the reader, to instruct the reader to only load the sheets with a given name:
|
You can set the option setLoadSheetsOnly on the reader, to instruct the reader to only load the sheets with a given name:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
$objReader->setLoadSheetsOnly( array("Sheet 1", "My special sheet") );
|
$reader->setLoadSheetsOnly( array("Sheet 1", "My special sheet") );
|
||||||
$spreadsheet = $objReader->load("05featuredemo.xlsx");
|
$spreadsheet = $reader->load("05featuredemo.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read specific cells only
|
#### Read specific cells only
|
||||||
|
@ -761,9 +761,9 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
$objReader->setReadFilter( new MyReadFilter() );
|
$reader->setReadFilter( new MyReadFilter() );
|
||||||
$spreadsheet = $objReader->load("06largescale.xlsx");
|
$spreadsheet = $reader->load("06largescale.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
### \PhpOffice\PhpSpreadsheet\Writer\Xlsx
|
### \PhpOffice\PhpSpreadsheet\Writer\Xlsx
|
||||||
|
@ -773,8 +773,8 @@ $spreadsheet = $objReader->load("06largescale.xlsx");
|
||||||
You can write an .xlsx file using the following code:
|
You can write an .xlsx file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
||||||
$objWriter->save("05featuredemo.xlsx");
|
$writer->save("05featuredemo.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Formula pre-calculation
|
#### Formula pre-calculation
|
||||||
|
@ -782,9 +782,9 @@ $objWriter->save("05featuredemo.xlsx");
|
||||||
By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation:
|
By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
||||||
$objWriter->setPreCalculateFormulas(false);
|
$writer->setPreCalculateFormulas(false);
|
||||||
$objWriter->save("05featuredemo.xlsx");
|
$writer->save("05featuredemo.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Office 2003 compatibility pack
|
#### Office 2003 compatibility pack
|
||||||
|
@ -792,9 +792,9 @@ $objWriter->save("05featuredemo.xlsx");
|
||||||
Because of a bug in the Office2003 compatibility pack, there can be some small issues when opening Xlsx spreadsheets (mostly related to formula calculation). You can enable Office2003 compatibility with the following code:
|
Because of a bug in the Office2003 compatibility pack, there can be some small issues when opening Xlsx spreadsheets (mostly related to formula calculation). You can enable Office2003 compatibility with the following code:
|
||||||
|
|
||||||
```
|
```
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
||||||
$objWriter->setOffice2003Compatibility(true);
|
$writer->setOffice2003Compatibility(true);
|
||||||
$objWriter->save("05featuredemo.xlsx");
|
$writer->save("05featuredemo.xlsx");
|
||||||
```
|
```
|
||||||
|
|
||||||
__Office2003 compatibility should only be used when needed__
|
__Office2003 compatibility should only be used when needed__
|
||||||
|
@ -816,8 +816,8 @@ Please note that BIFF file format has some limits regarding to styling cells and
|
||||||
You can read an .xls file using the following code:
|
You can read an .xls file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
||||||
$spreadsheet = $objReader->load("05featuredemo.xls");
|
$spreadsheet = $reader->load("05featuredemo.xls");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read data only
|
#### Read data only
|
||||||
|
@ -825,9 +825,9 @@ $spreadsheet = $objReader->load("05featuredemo.xls");
|
||||||
You can set the option setReadDataOnly on the reader, to instruct the reader to ignore styling, data validation, … and just read cell data:
|
You can set the option setReadDataOnly on the reader, to instruct the reader to ignore styling, data validation, … and just read cell data:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
||||||
$objReader->setReadDataOnly(true);
|
$reader->setReadDataOnly(true);
|
||||||
$spreadsheet = $objReader->load("05featuredemo.xls");
|
$spreadsheet = $reader->load("05featuredemo.xls");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read specific sheets only
|
#### Read specific sheets only
|
||||||
|
@ -835,9 +835,9 @@ $spreadsheet = $objReader->load("05featuredemo.xls");
|
||||||
You can set the option setLoadSheetsOnly on the reader, to instruct the reader to only load the sheets with a given name:
|
You can set the option setLoadSheetsOnly on the reader, to instruct the reader to only load the sheets with a given name:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
||||||
$objReader->setLoadSheetsOnly( array("Sheet 1", "My special sheet") );
|
$reader->setLoadSheetsOnly( array("Sheet 1", "My special sheet") );
|
||||||
$spreadsheet = $objReader->load("05featuredemo.xls");
|
$spreadsheet = $reader->load("05featuredemo.xls");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read specific cells only
|
#### Read specific cells only
|
||||||
|
@ -858,9 +858,9 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
||||||
$objReader->setReadFilter( new MyReadFilter() );
|
$reader->setReadFilter( new MyReadFilter() );
|
||||||
$spreadsheet = $objReader->load("06largescale.xls");
|
$spreadsheet = $reader->load("06largescale.xls");
|
||||||
```
|
```
|
||||||
|
|
||||||
### \PhpOffice\PhpSpreadsheet\Writer\Xls
|
### \PhpOffice\PhpSpreadsheet\Writer\Xls
|
||||||
|
@ -870,8 +870,8 @@ $spreadsheet = $objReader->load("06largescale.xls");
|
||||||
You can write an .xls file using the following code:
|
You can write an .xls file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xls($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xls($spreadsheet);
|
||||||
$objWriter->save("05featuredemo.xls");
|
$writer->save("05featuredemo.xls");
|
||||||
```
|
```
|
||||||
|
|
||||||
## Excel 2003 XML file format
|
## Excel 2003 XML file format
|
||||||
|
@ -888,8 +888,8 @@ Please note that Excel 2003 XML format has some limits regarding to styling cell
|
||||||
You can read an Excel 2003 .xml file using the following code:
|
You can read an Excel 2003 .xml file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Excel2003XML();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Excel2003XML();
|
||||||
$spreadsheet = $objReader->load("05featuredemo.xml");
|
$spreadsheet = $reader->load("05featuredemo.xml");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read specific cells only
|
#### Read specific cells only
|
||||||
|
@ -911,9 +911,9 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Excel2003XML();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Excel2003XML();
|
||||||
$objReader->setReadFilter( new MyReadFilter() );
|
$reader->setReadFilter( new MyReadFilter() );
|
||||||
$spreadsheet = $objReader->load("06largescale.xml");
|
$spreadsheet = $reader->load("06largescale.xml");
|
||||||
```
|
```
|
||||||
|
|
||||||
## Symbolic LinK (SYLK)
|
## Symbolic LinK (SYLK)
|
||||||
|
@ -930,8 +930,8 @@ Please note that SYLK file format has some limits regarding to styling cells and
|
||||||
You can read an .slk file using the following code:
|
You can read an .slk file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\SYLK();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\SYLK();
|
||||||
$spreadsheet = $objReader->load("05featuredemo.slk");
|
$spreadsheet = $reader->load("05featuredemo.slk");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read specific cells only
|
#### Read specific cells only
|
||||||
|
@ -953,9 +953,9 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\SYLK();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\SYLK();
|
||||||
$objReader->setReadFilter( new MyReadFilter() );
|
$reader->setReadFilter( new MyReadFilter() );
|
||||||
$spreadsheet = $objReader->load("06largescale.slk");
|
$spreadsheet = $reader->load("06largescale.slk");
|
||||||
```
|
```
|
||||||
|
|
||||||
## Open/Libre Office (.ods)
|
## Open/Libre Office (.ods)
|
||||||
|
@ -969,8 +969,8 @@ Open Office or Libre Office .ods files are the standard file format for Open Off
|
||||||
You can read an .ods file using the following code:
|
You can read an .ods file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Ods();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Ods();
|
||||||
$spreadsheet = $objReader->load("05featuredemo.ods");
|
$spreadsheet = $reader->load("05featuredemo.ods");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read specific cells only
|
#### Read specific cells only
|
||||||
|
@ -992,9 +992,9 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$objReader = new PhpOffice\PhpSpreadsheet\Reader\Ods();
|
$reader = new PhpOffice\PhpSpreadsheet\Reader\Ods();
|
||||||
$objReader->setReadFilter( new MyReadFilter() );
|
$reader->setReadFilter( new MyReadFilter() );
|
||||||
$spreadsheet = $objReader->load("06largescale.ods");
|
$spreadsheet = $reader->load("06largescale.ods");
|
||||||
```
|
```
|
||||||
|
|
||||||
## CSV (Comma Separated Values)
|
## CSV (Comma Separated Values)
|
||||||
|
@ -1011,8 +1011,8 @@ Please note that CSV file format has some limits regarding to styling cells, num
|
||||||
You can read a .csv file using the following code:
|
You can read a .csv file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
||||||
$spreadsheet = $objReader->load("sample.csv");
|
$spreadsheet = $reader->load("sample.csv");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Setting CSV options
|
#### Setting CSV options
|
||||||
|
@ -1022,14 +1022,14 @@ Often, CSV files are not really “comma separated”, or use semicolon (;) as a
|
||||||
Note that \PhpOffice\PhpSpreadsheet\Reader\CSV by default assumes that the loaded CSV file is UTF-8 encoded. If you are reading CSV files that were created in Microsoft Office Excel the correct input encoding may rather be Windows-1252 (CP1252). Always make sure that the input encoding is set appropriately.
|
Note that \PhpOffice\PhpSpreadsheet\Reader\CSV by default assumes that the loaded CSV file is UTF-8 encoded. If you are reading CSV files that were created in Microsoft Office Excel the correct input encoding may rather be Windows-1252 (CP1252). Always make sure that the input encoding is set appropriately.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
||||||
$objReader->setInputEncoding('CP1252');
|
$reader->setInputEncoding('CP1252');
|
||||||
$objReader->setDelimiter(';');
|
$reader->setDelimiter(';');
|
||||||
$objReader->setEnclosure('');
|
$reader->setEnclosure('');
|
||||||
$objReader->setLineEnding("\r\n");
|
$reader->setLineEnding("\r\n");
|
||||||
$objReader->setSheetIndex(0);
|
$reader->setSheetIndex(0);
|
||||||
|
|
||||||
$spreadsheet = $objReader->load("sample.csv");
|
$spreadsheet = $reader->load("sample.csv");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read a specific worksheet
|
#### Read a specific worksheet
|
||||||
|
@ -1037,7 +1037,7 @@ $spreadsheet = $objReader->load("sample.csv");
|
||||||
CSV files can only contain one worksheet. Therefore, you can specify which sheet to read from CSV:
|
CSV files can only contain one worksheet. Therefore, you can specify which sheet to read from CSV:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader->setSheetIndex(0);
|
$reader->setSheetIndex(0);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Read into existing spreadsheet
|
#### Read into existing spreadsheet
|
||||||
|
@ -1045,13 +1045,13 @@ $objReader->setSheetIndex(0);
|
||||||
When working with CSV files, it might occur that you want to import CSV data into an existing `Spreadsheet` object. The following code loads a CSV file into an existing $spreadsheet containing some sheets, and imports onto the 6th sheet:
|
When working with CSV files, it might occur that you want to import CSV data into an existing `Spreadsheet` object. The following code loads a CSV file into an existing $spreadsheet containing some sheets, and imports onto the 6th sheet:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
||||||
$objReader->setDelimiter(';');
|
$reader->setDelimiter(';');
|
||||||
$objReader->setEnclosure('');
|
$reader->setEnclosure('');
|
||||||
$objReader->setLineEnding("\r\n");
|
$reader->setLineEnding("\r\n");
|
||||||
$objReader->setSheetIndex(5);
|
$reader->setSheetIndex(5);
|
||||||
|
|
||||||
$objReader->loadIntoExisting("05featuredemo.csv", $spreadsheet);
|
$reader->loadIntoExisting("05featuredemo.csv", $spreadsheet);
|
||||||
```
|
```
|
||||||
|
|
||||||
### \PhpOffice\PhpSpreadsheet\Writer\CSV
|
### \PhpOffice\PhpSpreadsheet\Writer\CSV
|
||||||
|
@ -1061,8 +1061,8 @@ $objReader->loadIntoExisting("05featuredemo.csv", $spreadsheet);
|
||||||
You can write a .csv file using the following code:
|
You can write a .csv file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\CSV($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\CSV($spreadsheet);
|
||||||
$objWriter->save("05featuredemo.csv");
|
$writer->save("05featuredemo.csv");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Setting CSV options
|
#### Setting CSV options
|
||||||
|
@ -1070,13 +1070,13 @@ $objWriter->save("05featuredemo.csv");
|
||||||
Often, CSV files are not really “comma separated”, or use semicolon (;) as a separator. You can instruct \PhpOffice\PhpSpreadsheet\Writer\CSV some options before writing a CSV file:
|
Often, CSV files are not really “comma separated”, or use semicolon (;) as a separator. You can instruct \PhpOffice\PhpSpreadsheet\Writer\CSV some options before writing a CSV file:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\CSV($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\CSV($spreadsheet);
|
||||||
$objWriter->setDelimiter(';');
|
$writer->setDelimiter(';');
|
||||||
$objWriter->setEnclosure('');
|
$writer->setEnclosure('');
|
||||||
$objWriter->setLineEnding("\r\n");
|
$writer->setLineEnding("\r\n");
|
||||||
$objWriter->setSheetIndex(0);
|
$writer->setSheetIndex(0);
|
||||||
|
|
||||||
$objWriter->save("05featuredemo.csv");
|
$writer->save("05featuredemo.csv");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Write a specific worksheet
|
#### Write a specific worksheet
|
||||||
|
@ -1084,7 +1084,7 @@ $objWriter->save("05featuredemo.csv");
|
||||||
CSV files can only contain one worksheet. Therefore, you can specify which sheet to write to CSV:
|
CSV files can only contain one worksheet. Therefore, you can specify which sheet to write to CSV:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter->setSheetIndex(0);
|
$writer->setSheetIndex(0);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Formula pre-calculation
|
#### Formula pre-calculation
|
||||||
|
@ -1092,9 +1092,9 @@ $objWriter->setSheetIndex(0);
|
||||||
By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation:
|
By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\CSV($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\CSV($spreadsheet);
|
||||||
$objWriter->setPreCalculateFormulas(false);
|
$writer->setPreCalculateFormulas(false);
|
||||||
$objWriter->save("05featuredemo.csv");
|
$writer->save("05featuredemo.csv");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Writing UTF-8 CSV files
|
#### Writing UTF-8 CSV files
|
||||||
|
@ -1102,9 +1102,9 @@ $objWriter->save("05featuredemo.csv");
|
||||||
A CSV file can be marked as UTF-8 by writing a BOM file header. This can be enabled by using the following code:
|
A CSV file can be marked as UTF-8 by writing a BOM file header. This can be enabled by using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\CSV($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\CSV($spreadsheet);
|
||||||
$objWriter->setUseBOM(true);
|
$writer->setUseBOM(true);
|
||||||
$objWriter->save("05featuredemo.csv");
|
$writer->save("05featuredemo.csv");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Decimal and thousands separators
|
#### Decimal and thousands separators
|
||||||
|
@ -1143,9 +1143,9 @@ Please note that HTML file format has some limits regarding to styling cells, nu
|
||||||
You can read an .html or .htm file using the following code:
|
You can read an .html or .htm file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\HTML();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\HTML();
|
||||||
|
|
||||||
$spreadsheet = $objReader->load("05featuredemo.html");
|
$spreadsheet = $reader->load("05featuredemo.html");
|
||||||
```
|
```
|
||||||
|
|
||||||
__HTML limitations__
|
__HTML limitations__
|
||||||
|
@ -1160,9 +1160,9 @@ Please note that \PhpOffice\PhpSpreadsheet\Writer\HTML only outputs the first wo
|
||||||
You can write a .htm file using the following code:
|
You can write a .htm file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\HTML($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\HTML($spreadsheet);
|
||||||
|
|
||||||
$objWriter->save("05featuredemo.htm");
|
$writer->save("05featuredemo.htm");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Write all worksheets
|
#### Write all worksheets
|
||||||
|
@ -1170,7 +1170,7 @@ $objWriter->save("05featuredemo.htm");
|
||||||
HTML files can contain one or more worksheets. If you want to write all sheets into a single HTML file, use the following code:
|
HTML files can contain one or more worksheets. If you want to write all sheets into a single HTML file, use the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter->writeAllSheets();
|
$writer->writeAllSheets();
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Write a specific worksheet
|
#### Write a specific worksheet
|
||||||
|
@ -1178,7 +1178,7 @@ $objWriter->writeAllSheets();
|
||||||
HTML files can contain one or more worksheets. Therefore, you can specify which sheet to write to HTML:
|
HTML files can contain one or more worksheets. Therefore, you can specify which sheet to write to HTML:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter->setSheetIndex(0);
|
$writer->setSheetIndex(0);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Setting the images root of the HTML file
|
#### Setting the images root of the HTML file
|
||||||
|
@ -1197,7 +1197,7 @@ instead of
|
||||||
You can use the following code to achieve this result:
|
You can use the following code to achieve this result:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter->setImagesRoot('http://www.example.com');
|
$writer->setImagesRoot('http://www.example.com');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Formula pre-calculation
|
#### Formula pre-calculation
|
||||||
|
@ -1205,10 +1205,10 @@ $objWriter->setImagesRoot('http://www.example.com');
|
||||||
By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation:
|
By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\HTML($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\HTML($spreadsheet);
|
||||||
$objWriter->setPreCalculateFormulas(false);
|
$writer->setPreCalculateFormulas(false);
|
||||||
|
|
||||||
$objWriter->save("05featuredemo.htm");
|
$writer->save("05featuredemo.htm");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Embedding generated HTML in a web page
|
#### Embedding generated HTML in a web page
|
||||||
|
@ -1226,8 +1226,8 @@ Here's an example which retrieves all parts independently and merges them into a
|
||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\HTML($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\HTML($spreadsheet);
|
||||||
echo $objWriter->generateHTMLHeader();
|
echo $writer->generateHTMLHeader();
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -1239,15 +1239,15 @@ html {
|
||||||
}
|
}
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
echo $objWriter->generateStyles(false); // do not write <style> and </style>
|
echo $writer->generateStyles(false); // do not write <style> and </style>
|
||||||
?>
|
?>
|
||||||
|
|
||||||
-->
|
-->
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
echo $objWriter->generateSheetData();
|
echo $writer->generateSheetData();
|
||||||
echo $objWriter->generateHTMLFooter();
|
echo $writer->generateHTMLFooter();
|
||||||
?>
|
?>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1256,10 +1256,10 @@ echo $objWriter->generateHTMLFooter();
|
||||||
A HTML file can be marked as UTF-8 by writing a BOM file header. This can be enabled by using the following code:
|
A HTML file can be marked as UTF-8 by writing a BOM file header. This can be enabled by using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\HTML($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\HTML($spreadsheet);
|
||||||
$objWriter->setUseBOM(true);
|
$writer->setUseBOM(true);
|
||||||
|
|
||||||
$objWriter->save("05featuredemo.htm");
|
$writer->save("05featuredemo.htm");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Decimal and thousands separators
|
#### Decimal and thousands separators
|
||||||
|
@ -1311,8 +1311,8 @@ if (!\PhpOffice\PhpSpreadsheet\Settings::setPdfRenderer(
|
||||||
Once you have identified the Renderer that you wish to use for PDF generation, you can write a .pdf file using the following code:
|
Once you have identified the Renderer that you wish to use for PDF generation, you can write a .pdf file using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\PDF($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\PDF($spreadsheet);
|
||||||
$objWriter->save("05featuredemo.pdf");
|
$writer->save("05featuredemo.pdf");
|
||||||
```
|
```
|
||||||
|
|
||||||
Please note that \PhpOffice\PhpSpreadsheet\Writer\PDF only outputs the first worksheet by default.
|
Please note that \PhpOffice\PhpSpreadsheet\Writer\PDF only outputs the first worksheet by default.
|
||||||
|
@ -1322,7 +1322,7 @@ Please note that \PhpOffice\PhpSpreadsheet\Writer\PDF only outputs the first wor
|
||||||
PDF files can contain one or more worksheets. If you want to write all sheets into a single PDF file, use the following code:
|
PDF files can contain one or more worksheets. If you want to write all sheets into a single PDF file, use the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter->writeAllSheets();
|
$writer->writeAllSheets();
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Write a specific worksheet
|
#### Write a specific worksheet
|
||||||
|
@ -1330,7 +1330,7 @@ $objWriter->writeAllSheets();
|
||||||
PDF files can contain one or more worksheets. Therefore, you can specify which sheet to write to PDF:
|
PDF files can contain one or more worksheets. Therefore, you can specify which sheet to write to PDF:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter->setSheetIndex(0);
|
$writer->setSheetIndex(0);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Formula pre-calculation
|
#### Formula pre-calculation
|
||||||
|
@ -1338,10 +1338,10 @@ $objWriter->setSheetIndex(0);
|
||||||
By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation:
|
By default, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. You can however disable formula pre-calculation:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWriter = new \PhpOffice\PhpSpreadsheet\Writer\PDF($spreadsheet);
|
$writer = new \PhpOffice\PhpSpreadsheet\Writer\PDF($spreadsheet);
|
||||||
$objWriter->setPreCalculateFormulas(false);
|
$writer->setPreCalculateFormulas(false);
|
||||||
|
|
||||||
$objWriter->save("05featuredemo.pdf");
|
$writer->save("05featuredemo.pdf");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Decimal and thousands separators
|
#### Decimal and thousands separators
|
||||||
|
@ -1357,13 +1357,13 @@ Here is an example how to open a template file, fill in a couple of fields and s
|
||||||
```php
|
```php
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('template.xlsx');
|
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('template.xlsx');
|
||||||
|
|
||||||
$objWorksheet = $spreadsheet->getActiveSheet();
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
$objWorksheet->getCell('A1')->setValue('John');
|
$worksheet->getCell('A1')->setValue('John');
|
||||||
$objWorksheet->getCell('A2')->setValue('Smith');
|
$worksheet->getCell('A2')->setValue('Smith');
|
||||||
|
|
||||||
$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
|
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
|
||||||
$objWriter->save('write.xls');
|
$writer->save('write.xls');
|
||||||
```
|
```
|
||||||
|
|
||||||
Notice that it is ok to load an xlsx file and generate an xls file.
|
Notice that it is ok to load an xlsx file and generate an xls file.
|
||||||
|
|
|
@ -39,15 +39,15 @@ If you know the file type of the spreadsheet file that you need to load, you can
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
/** Create a new Xls Reader **/
|
/** Create a new Xls Reader **/
|
||||||
$objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\Excel2003XML();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Excel2003XML();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\Ods();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Ods();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\SYLK();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\SYLK();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\Gnumeric();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Gnumeric();
|
||||||
// $objReader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\CSV();
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader02.php for a working example of this code.
|
> See Examples/Reader/exampleReader02.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader03.php for a working example of this code.
|
> See Examples/Reader/exampleReader03.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -78,9 +78,9 @@ $inputFileName = './sampleData/example1.xls';
|
||||||
/** Identify the type of $inputFileName **/
|
/** Identify the type of $inputFileName **/
|
||||||
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
|
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
|
||||||
/** Create a new Reader of the type that has been identified **/
|
/** Create a new Reader of the type that has been identified **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader04.php for a working example of this code.
|
> See Examples/Reader/exampleReader04.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -97,11 +97,11 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Advise the Reader that we only want to load cell data **/
|
/** Advise the Reader that we only want to load cell data **/
|
||||||
$objReader->setReadDataOnly(true);
|
$reader->setReadDataOnly(true);
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader05.php for a working example of this code.
|
> See Examples/Reader/exampleReader05.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -129,11 +129,11 @@ $inputFileName = './sampleData/example1.xls';
|
||||||
$sheetname = 'Data Sheet #2';
|
$sheetname = 'Data Sheet #2';
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Advise the Reader of which WorkSheets we want to load **/
|
/** Advise the Reader of which WorkSheets we want to load **/
|
||||||
$objReader->setLoadSheetsOnly($sheetname);
|
$reader->setLoadSheetsOnly($sheetname);
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader07.php for a working example of this code.
|
> See Examples/Reader/exampleReader07.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -145,11 +145,11 @@ $inputFileName = './sampleData/example1.xls';
|
||||||
$sheetnames = array('Data Sheet #1','Data Sheet #3');
|
$sheetnames = array('Data Sheet #1','Data Sheet #3');
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Advise the Reader of which WorkSheets we want to load **/
|
/** Advise the Reader of which WorkSheets we want to load **/
|
||||||
$objReader->setLoadSheetsOnly($sheetnames);
|
$reader->setLoadSheetsOnly($sheetnames);
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader08.php for a working example of this code.
|
> See Examples/Reader/exampleReader08.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -160,11 +160,11 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Advise the Reader to load all Worksheets **/
|
/** Advise the Reader to load all Worksheets **/
|
||||||
$objReader->setLoadAllSheets();
|
$reader->setLoadAllSheets();
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader06.php for a working example of this code.
|
> See Examples/Reader/exampleReader06.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -204,11 +204,11 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||||
$filterSubset = new MyReadFilter();
|
$filterSubset = new MyReadFilter();
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Tell the Reader that we want to use the Read Filter **/
|
/** Tell the Reader that we want to use the Read Filter **/
|
||||||
$objReader->setReadFilter($filterSubset);
|
$reader->setReadFilter($filterSubset);
|
||||||
/** Load only the rows and columns that match our filter to Spreadsheet **/
|
/** Load only the rows and columns that match our filter to Spreadsheet **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader09.php for a working example of this code.
|
> See Examples/Reader/exampleReader09.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||||
|
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
|
|
||||||
/** Define how many rows we want to read for each "chunk" **/
|
/** Define how many rows we want to read for each "chunk" **/
|
||||||
|
@ -284,14 +284,14 @@ $chunkSize = 2048;
|
||||||
$chunkFilter = new chunkReadFilter();
|
$chunkFilter = new chunkReadFilter();
|
||||||
|
|
||||||
/** Tell the Reader that we want to use the Read Filter **/
|
/** Tell the Reader that we want to use the Read Filter **/
|
||||||
$objReader->setReadFilter($chunkFilter);
|
$reader->setReadFilter($chunkFilter);
|
||||||
|
|
||||||
/** Loop to read our worksheet in "chunk size" blocks **/
|
/** Loop to read our worksheet in "chunk size" blocks **/
|
||||||
for ($startRow = 2; $startRow <= 65536; $startRow += $chunkSize) {
|
for ($startRow = 2; $startRow <= 65536; $startRow += $chunkSize) {
|
||||||
/** Tell the Read Filter which rows we want this iteration **/
|
/** Tell the Read Filter which rows we want this iteration **/
|
||||||
$chunkFilter->setRows($startRow,$chunkSize);
|
$chunkFilter->setRows($startRow,$chunkSize);
|
||||||
/** Load only the rows that match our filter **/
|
/** Load only the rows that match our filter **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
// Do some processing here
|
// Do some processing here
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -307,7 +307,7 @@ CSV | YES | HTML | NO
|
||||||
|
|
||||||
### Combining Multiple Files into a Single Spreadsheet Object
|
### Combining Multiple Files into a Single Spreadsheet Object
|
||||||
|
|
||||||
While you can limit the number of worksheets that are read from a workbook file using the setLoadSheetsOnly() method, certain readers also allow you to combine several individual "sheets" from different files into a single `Spreadsheet` object, where each individual file is a single worksheet within that workbook. For each file that you read, you need to indicate which worksheet index it should be loaded into using the setSheetIndex() method of the $objReader, then use the loadIntoExisting() method rather than the load() method to actually read the file into that worksheet.
|
While you can limit the number of worksheets that are read from a workbook file using the setLoadSheetsOnly() method, certain readers also allow you to combine several individual "sheets" from different files into a single `Spreadsheet` object, where each individual file is a single worksheet within that workbook. For each file that you read, you need to indicate which worksheet index it should be loaded into using the setSheetIndex() method of the $reader, then use the loadIntoExisting() method rather than the load() method to actually read the file into that worksheet.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
|
@ -317,13 +317,13 @@ $inputFileNames = array('./sampleData/example1.csv',
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
|
|
||||||
/** Extract the first named file from the array list **/
|
/** Extract the first named file from the array list **/
|
||||||
$inputFileName = array_shift($inputFileNames);
|
$inputFileName = array_shift($inputFileNames);
|
||||||
/** Load the initial file to the first worksheet in a `Spreadsheet` Object **/
|
/** Load the initial file to the first worksheet in a `Spreadsheet` Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
/** Set the worksheet title (to the filename that we've loaded) **/
|
/** Set the worksheet title (to the filename that we've loaded) **/
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
||||||
|
@ -332,9 +332,9 @@ $spreadsheet->getActiveSheet()
|
||||||
/** Loop through all the remaining files in the list **/
|
/** Loop through all the remaining files in the list **/
|
||||||
foreach($inputFileNames as $sheet => $inputFileName) {
|
foreach($inputFileNames as $sheet => $inputFileName) {
|
||||||
/** Increment the worksheet index pointer for the Reader **/
|
/** Increment the worksheet index pointer for the Reader **/
|
||||||
$objReader->setSheetIndex($sheet+1);
|
$reader->setSheetIndex($sheet+1);
|
||||||
/** Load the current file into a new worksheet in Spreadsheet **/
|
/** Load the current file into a new worksheet in Spreadsheet **/
|
||||||
$objReader->loadIntoExisting($inputFileName,$spreadsheet);
|
$reader->loadIntoExisting($inputFileName,$spreadsheet);
|
||||||
/** Set the worksheet title (to the filename that we've loaded) **/
|
/** Set the worksheet title (to the filename that we've loaded) **/
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
||||||
|
@ -354,7 +354,7 @@ CSV | YES | HTML | NO
|
||||||
|
|
||||||
### Combining Read Filters with the setSheetIndex() method to split a large CSV file across multiple Worksheets
|
### Combining Read Filters with the setSheetIndex() method to split a large CSV file across multiple Worksheets
|
||||||
|
|
||||||
An Xls BIFF .xls file is limited to 65536 rows in a worksheet, while the Xlsx Microsoft Office Open XML SpreadsheetML .xlsx file is limited to 1,048,576 rows in a worksheet; but a CSV file is not limited other than by available disk space. This means that we wouldn’t ordinarily be able to read all the rows from a very large CSV file that exceeded those limits, and save it as an Xls or Xlsx file. However, by using Read Filters to read the CSV file in “chunks” (using the chunkReadFilter Class that we defined in section REF _Ref275604563 \r \p 5.3 above), and the setSheetIndex() method of the $objReader, we can split the CSV file across several individual worksheets.
|
An Xls BIFF .xls file is limited to 65536 rows in a worksheet, while the Xlsx Microsoft Office Open XML SpreadsheetML .xlsx file is limited to 1,048,576 rows in a worksheet; but a CSV file is not limited other than by available disk space. This means that we wouldn’t ordinarily be able to read all the rows from a very large CSV file that exceeded those limits, and save it as an Xls or Xlsx file. However, by using Read Filters to read the CSV file in “chunks” (using the chunkReadFilter Class that we defined in section REF _Ref275604563 \r \p 5.3 above), and the setSheetIndex() method of the $reader, we can split the CSV file across several individual worksheets.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
|
@ -363,7 +363,7 @@ $inputFileName = './sampleData/example2.csv';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
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 **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
|
|
||||||
/** Define how many rows we want to read for each "chunk" **/
|
/** Define how many rows we want to read for each "chunk" **/
|
||||||
|
@ -374,7 +374,7 @@ $chunkFilter = new chunkReadFilter();
|
||||||
/** Tell the Reader that we want to use the Read Filter **/
|
/** Tell the Reader that we want to use the Read Filter **/
|
||||||
/** and that we want to store it in contiguous rows/columns **/
|
/** and that we want to store it in contiguous rows/columns **/
|
||||||
|
|
||||||
$objReader->setReadFilter($chunkFilter)
|
$reader->setReadFilter($chunkFilter)
|
||||||
->setContiguous(true);
|
->setContiguous(true);
|
||||||
|
|
||||||
/** Instantiate a new Spreadsheet object manually **/
|
/** Instantiate a new Spreadsheet object manually **/
|
||||||
|
@ -389,9 +389,9 @@ for ($startRow = 2; $startRow <= 1000000; $startRow += $chunkSize) {
|
||||||
$chunkFilter->setRows($startRow,$chunkSize);
|
$chunkFilter->setRows($startRow,$chunkSize);
|
||||||
|
|
||||||
/** Increment the worksheet index pointer for the Reader **/
|
/** Increment the worksheet index pointer for the Reader **/
|
||||||
$objReader->setSheetIndex($sheet);
|
$reader->setSheetIndex($sheet);
|
||||||
/** Load only the rows that match our filter into a new worksheet **/
|
/** Load only the rows that match our filter into a new worksheet **/
|
||||||
$objReader->loadIntoExisting($inputFileName,$spreadsheet);
|
$reader->loadIntoExisting($inputFileName,$spreadsheet);
|
||||||
/** Set the worksheet title for the sheet that we've justloaded) **/
|
/** Set the worksheet title for the sheet that we've justloaded) **/
|
||||||
/** and increment the sheet index as well **/
|
/** and increment the sheet index as well **/
|
||||||
$spreadsheet->getActiveSheet()->setTitle('Country Data #'.(++$sheet));
|
$spreadsheet->getActiveSheet()->setTitle('Country Data #'.(++$sheet));
|
||||||
|
@ -421,13 +421,13 @@ The CSV loader defaults to loading a file where comma is used as the separator,
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
$inputFileName = './sampleData/example1.tsv';
|
$inputFileName = './sampleData/example1.tsv';
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/ $objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
/** Create a new Reader of the type defined in $inputFileType **/ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Set the delimiter to a TAB character **/
|
/** Set the delimiter to a TAB character **/
|
||||||
$objReader->setDelimiter("\t");
|
$reader->setDelimiter("\t");
|
||||||
// $objReader->setDelimiter('|');
|
// $reader->setDelimiter('|');
|
||||||
|
|
||||||
/** Load the file to a Spreadsheet Object **/
|
/** Load the file to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader15.php for a working example of this code.
|
> See Examples/Reader/exampleReader15.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -460,9 +460,9 @@ So using a Value Binder allows a great deal more flexibility in the loader logic
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
$inputFileName = './sampleData/example1.tsv';
|
$inputFileName = './sampleData/example1.tsv';
|
||||||
|
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
$objReader->setDelimiter("\t");
|
$reader->setDelimiter("\t");
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader15.php for a working example of this code.
|
> See Examples/Reader/exampleReader15.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -489,11 +489,11 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Advise the Reader that we only want to load cell data **/
|
/** Advise the Reader that we only want to load cell data **/
|
||||||
$objReader->setReadDataOnly(true);
|
$reader->setReadDataOnly(true);
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader05.php for a working example of this code.
|
> See Examples/Reader/exampleReader05.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -521,11 +521,11 @@ $inputFileName = './sampleData/example1.xls';
|
||||||
$sheetname = 'Data Sheet #2';
|
$sheetname = 'Data Sheet #2';
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Advise the Reader of which WorkSheets we want to load **/
|
/** Advise the Reader of which WorkSheets we want to load **/
|
||||||
$objReader->setLoadSheetsOnly($sheetname);
|
$reader->setLoadSheetsOnly($sheetname);
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader07.php for a working example of this code.
|
> See Examples/Reader/exampleReader07.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -537,11 +537,11 @@ $inputFileName = './sampleData/example1.xls';
|
||||||
$sheetnames = array('Data Sheet #1','Data Sheet #3');
|
$sheetnames = array('Data Sheet #1','Data Sheet #3');
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Advise the Reader of which WorkSheets we want to load **/
|
/** Advise the Reader of which WorkSheets we want to load **/
|
||||||
$objReader->setLoadSheetsOnly($sheetnames);
|
$reader->setLoadSheetsOnly($sheetnames);
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader08.php for a working example of this code.
|
> See Examples/Reader/exampleReader08.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -552,11 +552,11 @@ $inputFileType = 'Xls';
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Advise the Reader to load all Worksheets **/
|
/** Advise the Reader to load all Worksheets **/
|
||||||
$objReader->setLoadAllSheets();
|
$reader->setLoadAllSheets();
|
||||||
/** Load $inputFileName to a Spreadsheet Object **/
|
/** Load $inputFileName to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader06.php for a working example of this code.
|
> See Examples/Reader/exampleReader06.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -596,11 +596,11 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||||
$filterSubset = new MyReadFilter();
|
$filterSubset = new MyReadFilter();
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Tell the Reader that we want to use the Read Filter **/
|
/** Tell the Reader that we want to use the Read Filter **/
|
||||||
$objReader->setReadFilter($filterSubset);
|
$reader->setReadFilter($filterSubset);
|
||||||
/** Load only the rows and columns that match our filter to Spreadsheet **/
|
/** Load only the rows and columns that match our filter to Spreadsheet **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader09.php for a working example of this code.
|
> See Examples/Reader/exampleReader09.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -667,7 +667,7 @@ class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||||
|
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
|
|
||||||
/** Define how many rows we want to read for each "chunk" **/
|
/** Define how many rows we want to read for each "chunk" **/
|
||||||
|
@ -676,14 +676,14 @@ $chunkSize = 2048;
|
||||||
$chunkFilter = new chunkReadFilter();
|
$chunkFilter = new chunkReadFilter();
|
||||||
|
|
||||||
/** Tell the Reader that we want to use the Read Filter **/
|
/** Tell the Reader that we want to use the Read Filter **/
|
||||||
$objReader->setReadFilter($chunkFilter);
|
$reader->setReadFilter($chunkFilter);
|
||||||
|
|
||||||
/** Loop to read our worksheet in "chunk size" blocks **/
|
/** Loop to read our worksheet in "chunk size" blocks **/
|
||||||
for ($startRow = 2; $startRow <= 65536; $startRow += $chunkSize) {
|
for ($startRow = 2; $startRow <= 65536; $startRow += $chunkSize) {
|
||||||
/** Tell the Read Filter which rows we want this iteration **/
|
/** Tell the Read Filter which rows we want this iteration **/
|
||||||
$chunkFilter->setRows($startRow,$chunkSize);
|
$chunkFilter->setRows($startRow,$chunkSize);
|
||||||
/** Load only the rows that match our filter **/
|
/** Load only the rows that match our filter **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
// Do some processing here
|
// Do some processing here
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -699,7 +699,7 @@ CSV | YES | HTML | NO
|
||||||
|
|
||||||
### Combining Multiple Files into a Single Spreadsheet Object
|
### Combining Multiple Files into a Single Spreadsheet Object
|
||||||
|
|
||||||
While you can limit the number of worksheets that are read from a workbook file using the setLoadSheetsOnly() method, certain readers also allow you to combine several individual "sheets" from different files into a single `Spreadsheet` object, where each individual file is a single worksheet within that workbook. For each file that you read, you need to indicate which worksheet index it should be loaded into using the setSheetIndex() method of the $objReader, then use the loadIntoExisting() method rather than the load() method to actually read the file into that worksheet.
|
While you can limit the number of worksheets that are read from a workbook file using the setLoadSheetsOnly() method, certain readers also allow you to combine several individual "sheets" from different files into a single `Spreadsheet` object, where each individual file is a single worksheet within that workbook. For each file that you read, you need to indicate which worksheet index it should be loaded into using the setSheetIndex() method of the $reader, then use the loadIntoExisting() method rather than the load() method to actually read the file into that worksheet.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
|
@ -709,13 +709,13 @@ $inputFileNames = array('./sampleData/example1.csv',
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
|
|
||||||
/** Extract the first named file from the array list **/
|
/** Extract the first named file from the array list **/
|
||||||
$inputFileName = array_shift($inputFileNames);
|
$inputFileName = array_shift($inputFileNames);
|
||||||
/** Load the initial file to the first worksheet in a `Spreadsheet` Object **/
|
/** Load the initial file to the first worksheet in a `Spreadsheet` Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
/** Set the worksheet title (to the filename that we've loaded) **/
|
/** Set the worksheet title (to the filename that we've loaded) **/
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
||||||
|
@ -724,9 +724,9 @@ $spreadsheet->getActiveSheet()
|
||||||
/** Loop through all the remaining files in the list **/
|
/** Loop through all the remaining files in the list **/
|
||||||
foreach($inputFileNames as $sheet => $inputFileName) {
|
foreach($inputFileNames as $sheet => $inputFileName) {
|
||||||
/** Increment the worksheet index pointer for the Reader **/
|
/** Increment the worksheet index pointer for the Reader **/
|
||||||
$objReader->setSheetIndex($sheet+1);
|
$reader->setSheetIndex($sheet+1);
|
||||||
/** Load the current file into a new worksheet in Spreadsheet **/
|
/** Load the current file into a new worksheet in Spreadsheet **/
|
||||||
$objReader->loadIntoExisting($inputFileName,$spreadsheet);
|
$reader->loadIntoExisting($inputFileName,$spreadsheet);
|
||||||
/** Set the worksheet title (to the filename that we've loaded) **/
|
/** Set the worksheet title (to the filename that we've loaded) **/
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
||||||
|
@ -746,7 +746,7 @@ CSV | YES | HTML | NO
|
||||||
|
|
||||||
### Combining Read Filters with the setSheetIndex() method to split a large CSV file across multiple Worksheets
|
### Combining Read Filters with the setSheetIndex() method to split a large CSV file across multiple Worksheets
|
||||||
|
|
||||||
An Xls BIFF .xls file is limited to 65536 rows in a worksheet, while the Xlsx Microsoft Office Open XML SpreadsheetML .xlsx file is limited to 1,048,576 rows in a worksheet; but a CSV file is not limited other than by available disk space. This means that we wouldn’t ordinarily be able to read all the rows from a very large CSV file that exceeded those limits, and save it as an Xls or Xlsx file. However, by using Read Filters to read the CSV file in “chunks” (using the chunkReadFilter Class that we defined in section REF _Ref275604563 \r \p 5.3 above), and the setSheetIndex() method of the $objReader, we can split the CSV file across several individual worksheets.
|
An Xls BIFF .xls file is limited to 65536 rows in a worksheet, while the Xlsx Microsoft Office Open XML SpreadsheetML .xlsx file is limited to 1,048,576 rows in a worksheet; but a CSV file is not limited other than by available disk space. This means that we wouldn’t ordinarily be able to read all the rows from a very large CSV file that exceeded those limits, and save it as an Xls or Xlsx file. However, by using Read Filters to read the CSV file in “chunks” (using the chunkReadFilter Class that we defined in section REF _Ref275604563 \r \p 5.3 above), and the setSheetIndex() method of the $reader, we can split the CSV file across several individual worksheets.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
|
@ -755,7 +755,7 @@ $inputFileName = './sampleData/example2.csv';
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
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 **/
|
/** Create a new Reader of the type defined in $inputFileType **/
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
|
|
||||||
/** Define how many rows we want to read for each "chunk" **/
|
/** Define how many rows we want to read for each "chunk" **/
|
||||||
|
@ -766,7 +766,7 @@ $chunkFilter = new chunkReadFilter();
|
||||||
/** Tell the Reader that we want to use the Read Filter **/
|
/** Tell the Reader that we want to use the Read Filter **/
|
||||||
/** and that we want to store it in contiguous rows/columns **/
|
/** and that we want to store it in contiguous rows/columns **/
|
||||||
|
|
||||||
$objReader->setReadFilter($chunkFilter)
|
$reader->setReadFilter($chunkFilter)
|
||||||
->setContiguous(true);
|
->setContiguous(true);
|
||||||
|
|
||||||
/** Instantiate a new Spreadsheet object manually **/
|
/** Instantiate a new Spreadsheet object manually **/
|
||||||
|
@ -781,9 +781,9 @@ for ($startRow = 2; $startRow <= 1000000; $startRow += $chunkSize) {
|
||||||
$chunkFilter->setRows($startRow,$chunkSize);
|
$chunkFilter->setRows($startRow,$chunkSize);
|
||||||
|
|
||||||
/** Increment the worksheet index pointer for the Reader **/
|
/** Increment the worksheet index pointer for the Reader **/
|
||||||
$objReader->setSheetIndex($sheet);
|
$reader->setSheetIndex($sheet);
|
||||||
/** Load only the rows that match our filter into a new worksheet **/
|
/** Load only the rows that match our filter into a new worksheet **/
|
||||||
$objReader->loadIntoExisting($inputFileName,$spreadsheet);
|
$reader->loadIntoExisting($inputFileName,$spreadsheet);
|
||||||
/** Set the worksheet title for the sheet that we've justloaded) **/
|
/** Set the worksheet title for the sheet that we've justloaded) **/
|
||||||
/** and increment the sheet index as well **/
|
/** and increment the sheet index as well **/
|
||||||
$spreadsheet->getActiveSheet()->setTitle('Country Data #'.(++$sheet));
|
$spreadsheet->getActiveSheet()->setTitle('Country Data #'.(++$sheet));
|
||||||
|
@ -813,13 +813,13 @@ The CSV loader defaults to loading a file where comma is used as the separator,
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
$inputFileName = './sampleData/example1.tsv';
|
$inputFileName = './sampleData/example1.tsv';
|
||||||
|
|
||||||
/** Create a new Reader of the type defined in $inputFileType **/ $objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
/** Create a new Reader of the type defined in $inputFileType **/ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
/** Set the delimiter to a TAB character **/
|
/** Set the delimiter to a TAB character **/
|
||||||
$objReader->setDelimiter("\t");
|
$reader->setDelimiter("\t");
|
||||||
// $objReader->setDelimiter('|');
|
// $reader->setDelimiter('|');
|
||||||
|
|
||||||
/** Load the file to a Spreadsheet Object **/
|
/** Load the file to a Spreadsheet Object **/
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader15.php for a working example of this code.
|
> See Examples/Reader/exampleReader15.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -852,9 +852,9 @@ So using a Value Binder allows a great deal more flexibility in the loader logic
|
||||||
$inputFileType = 'CSV';
|
$inputFileType = 'CSV';
|
||||||
$inputFileName = './sampleData/example1.tsv';
|
$inputFileName = './sampleData/example1.tsv';
|
||||||
|
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
$objReader->setDelimiter("\t");
|
$reader->setDelimiter("\t");
|
||||||
$spreadsheet = $objReader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
```
|
```
|
||||||
> See Examples/Reader/exampleReader15.php for a working example of this code.
|
> See Examples/Reader/exampleReader15.php for a working example of this code.
|
||||||
|
|
||||||
|
@ -897,9 +897,9 @@ You can retrieve a list of worksheet names contained in a file without loading t
|
||||||
The `listWorksheetNames()` method returns a simple array listing each worksheet name within the workbook:
|
The `listWorksheetNames()` method returns a simple array listing each worksheet name within the workbook:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
$worksheetNames = $objReader->listWorksheetNames($inputFileName);
|
$worksheetNames = $reader->listWorksheetNames($inputFileName);
|
||||||
|
|
||||||
echo '<h3>Worksheet Names</h3>';
|
echo '<h3>Worksheet Names</h3>';
|
||||||
echo '<ol>';
|
echo '<ol>';
|
||||||
|
@ -915,9 +915,9 @@ echo '</ol>';
|
||||||
The `listWorksheetInfo()` method returns a nested array, with each entry listing the name and dimensions for a worksheet:
|
The `listWorksheetInfo()` method returns a nested array, with each entry listing the name and dimensions for a worksheet:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
$worksheetData = $objReader->listWorksheetInfo($inputFileName);
|
$worksheetData = $reader->listWorksheetInfo($inputFileName);
|
||||||
|
|
||||||
echo '<h3>Worksheet Information</h3>';
|
echo '<h3>Worksheet Information</h3>';
|
||||||
echo '<ol>';
|
echo '<ol>';
|
||||||
|
|
|
@ -358,11 +358,11 @@ Code | Meaning
|
||||||
|
|
||||||
[^print-footer-image-footnote]: z
|
[^print-footer-image-footnote]: z
|
||||||
```php
|
```php
|
||||||
$objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing();
|
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing();
|
||||||
$objDrawing->setName('PhpSpreadsheet logo');
|
$drawing->setName('PhpSpreadsheet logo');
|
||||||
$objDrawing->setPath('./images/PhpSpreadsheet_logo.png');
|
$drawing->setPath('./images/PhpSpreadsheet_logo.png');
|
||||||
$objDrawing->setHeight(36);
|
$drawing->setHeight(36);
|
||||||
$spreadsheet->getActiveSheet()->getHeaderFooter()->addImage($objDrawing, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT);
|
$spreadsheet->getActiveSheet()->getHeaderFooter()->addImage($drawing, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT);
|
||||||
```
|
```
|
||||||
|
|
||||||
__Tip__
|
__Tip__
|
||||||
|
@ -371,12 +371,12 @@ The above table of codes may seem overwhelming first time you are trying to figu
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('test.xlsx');
|
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('test.xlsx');
|
||||||
$objWorksheet = $spreadsheet->getActiveSheet();
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
var_dump($objWorksheet->getHeaderFooter()->getOddFooter());
|
var_dump($worksheet->getHeaderFooter()->getOddFooter());
|
||||||
var_dump($objWorksheet->getHeaderFooter()->getEvenFooter());
|
var_dump($worksheet->getHeaderFooter()->getEvenFooter());
|
||||||
var_dump($objWorksheet->getHeaderFooter()->getOddHeader());
|
var_dump($worksheet->getHeaderFooter()->getOddHeader());
|
||||||
var_dump($objWorksheet->getHeaderFooter()->getEvenHeader());
|
var_dump($worksheet->getHeaderFooter()->getEvenHeader());
|
||||||
```
|
```
|
||||||
|
|
||||||
That reveals the codes for the even/odd header and footer. Experienced users may find it easier to rename test.xlsx to test.zip, unzip it, and inspect directly the contents of the relevant xl/worksheets/sheetX.xml to find the codes for header/footer.
|
That reveals the codes for the even/odd header and footer. Experienced users may find it easier to rename test.xlsx to test.zip, unzip it, and inspect directly the contents of the relevant xl/worksheets/sheetX.xml to find the codes for header/footer.
|
||||||
|
@ -542,8 +542,8 @@ The rules for composing a number format code in Excel can be rather complicated.
|
||||||
The readers shipped with PhpSpreadsheet come to the rescue. Load your template workbook using e.g. Xlsx reader to reveal the number format code. Example how read a number format code for cell A1:
|
The readers shipped with PhpSpreadsheet come to the rescue. Load your template workbook using e.g. Xlsx reader to reveal the number format code. Example how read a number format code for cell A1:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
||||||
$spreadsheet = $objReader->load('template.xlsx');
|
$spreadsheet = $reader->load('template.xlsx');
|
||||||
var_dump($spreadsheet->getActiveSheet()->getStyle('A1')->getNumberFormat()->getFormatCode());
|
var_dump($spreadsheet->getActiveSheet()->getStyle('A1')->getNumberFormat()->getFormatCode());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -588,7 +588,7 @@ $styleArray = array(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$objWorksheet->getStyle('B2:G8')->applyFromArray($styleArray);
|
$worksheet->getStyle('B2:G8')->applyFromArray($styleArray);
|
||||||
```
|
```
|
||||||
|
|
||||||
In Microsoft Office Excel, the above operation would correspond to selecting the cells B2:G8, launching the style dialog, choosing a thick red border, and clicking on the "Outline" border component.
|
In Microsoft Office Excel, the above operation would correspond to selecting the cells B2:G8, launching the style dialog, choosing a thick red border, and clicking on the "Outline" border component.
|
||||||
|
@ -722,23 +722,23 @@ A cell can be formatted conditionally, based on a specific rule. For example, on
|
||||||
One can set a conditional style ruleset to a cell using the following code:
|
One can set a conditional style ruleset to a cell using the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objConditional1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
|
$conditional1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
|
||||||
$objConditional1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS);
|
$conditional1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS);
|
||||||
$objConditional1->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN);
|
$conditional1->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN);
|
||||||
$objConditional1->addCondition('0');
|
$conditional1->addCondition('0');
|
||||||
$objConditional1->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
|
$conditional1->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
|
||||||
$objConditional1->getStyle()->getFont()->setBold(true);
|
$conditional1->getStyle()->getFont()->setBold(true);
|
||||||
|
|
||||||
$objConditional2 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
|
$conditional2 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
|
||||||
$objConditional2->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS);
|
$conditional2->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS);
|
||||||
$objConditional2->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHANOREQUAL);
|
$conditional2->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHANOREQUAL);
|
||||||
$objConditional2->addCondition('0');
|
$conditional2->addCondition('0');
|
||||||
$objConditional2->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
|
$conditional2->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
|
||||||
$objConditional2->getStyle()->getFont()->setBold(true);
|
$conditional2->getStyle()->getFont()->setBold(true);
|
||||||
|
|
||||||
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles();
|
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles();
|
||||||
array_push($conditionalStyles, $objConditional1);
|
array_push($conditionalStyles, $conditional1);
|
||||||
array_push($conditionalStyles, $objConditional2);
|
array_push($conditionalStyles, $conditional2);
|
||||||
|
|
||||||
$spreadsheet->getActiveSheet()->getStyle('B2')->setConditionalStyles($conditionalStyles);
|
$spreadsheet->getActiveSheet()->getStyle('B2')->setConditionalStyles($conditionalStyles);
|
||||||
```
|
```
|
||||||
|
@ -761,10 +761,10 @@ To add a comment to a cell, use the following code. The example below adds a com
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getComment('E11')
|
->getComment('E11')
|
||||||
->setAuthor('Mark Baker');
|
->setAuthor('Mark Baker');
|
||||||
$objCommentRichText = $spreadsheet->getActiveSheet()
|
$commentRichText = $spreadsheet->getActiveSheet()
|
||||||
->getComment('E11')
|
->getComment('E11')
|
||||||
->getText()->createTextRun('PhpSpreadsheet:');
|
->getText()->createTextRun('PhpSpreadsheet:');
|
||||||
$objCommentRichText->getFont()->setBold(true);
|
$commentRichText->getFont()->setBold(true);
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getComment('E11')
|
->getComment('E11')
|
||||||
->getText()->createTextRun("\r\n");
|
->getText()->createTextRun("\r\n");
|
||||||
|
@ -834,47 +834,47 @@ Data validation is a powerful feature of Xlsx. It allows to specify an input fil
|
||||||
The following piece of code only allows numbers between 10 and 20 to be entered in cell B3:
|
The following piece of code only allows numbers between 10 and 20 to be entered in cell B3:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objValidation = $spreadsheet->getActiveSheet()->getCell('B3')
|
$validation = $spreadsheet->getActiveSheet()->getCell('B3')
|
||||||
->getDataValidation();
|
->getDataValidation();
|
||||||
$objValidation->setType( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_WHOLE );
|
$validation->setType( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_WHOLE );
|
||||||
$objValidation->setErrorStyle( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_STOP );
|
$validation->setErrorStyle( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_STOP );
|
||||||
$objValidation->setAllowBlank(true);
|
$validation->setAllowBlank(true);
|
||||||
$objValidation->setShowInputMessage(true);
|
$validation->setShowInputMessage(true);
|
||||||
$objValidation->setShowErrorMessage(true);
|
$validation->setShowErrorMessage(true);
|
||||||
$objValidation->setErrorTitle('Input error');
|
$validation->setErrorTitle('Input error');
|
||||||
$objValidation->setError('Number is not allowed!');
|
$validation->setError('Number is not allowed!');
|
||||||
$objValidation->setPromptTitle('Allowed input');
|
$validation->setPromptTitle('Allowed input');
|
||||||
$objValidation->setPrompt('Only numbers between 10 and 20 are allowed.');
|
$validation->setPrompt('Only numbers between 10 and 20 are allowed.');
|
||||||
$objValidation->setFormula1(10);
|
$validation->setFormula1(10);
|
||||||
$objValidation->setFormula2(20);
|
$validation->setFormula2(20);
|
||||||
```
|
```
|
||||||
|
|
||||||
The following piece of code only allows an item picked from a list of data to be entered in cell B3:
|
The following piece of code only allows an item picked from a list of data to be entered in cell B3:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objValidation = $spreadsheet->getActiveSheet()->getCell('B5')
|
$validation = $spreadsheet->getActiveSheet()->getCell('B5')
|
||||||
->getDataValidation();
|
->getDataValidation();
|
||||||
$objValidation->setType( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST );
|
$validation->setType( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST );
|
||||||
$objValidation->setErrorStyle( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION );
|
$validation->setErrorStyle( \PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION );
|
||||||
$objValidation->setAllowBlank(false);
|
$validation->setAllowBlank(false);
|
||||||
$objValidation->setShowInputMessage(true);
|
$validation->setShowInputMessage(true);
|
||||||
$objValidation->setShowErrorMessage(true);
|
$validation->setShowErrorMessage(true);
|
||||||
$objValidation->setShowDropDown(true);
|
$validation->setShowDropDown(true);
|
||||||
$objValidation->setErrorTitle('Input error');
|
$validation->setErrorTitle('Input error');
|
||||||
$objValidation->setError('Value is not in list.');
|
$validation->setError('Value is not in list.');
|
||||||
$objValidation->setPromptTitle('Pick from list');
|
$validation->setPromptTitle('Pick from list');
|
||||||
$objValidation->setPrompt('Please pick a value from the drop-down list.');
|
$validation->setPrompt('Please pick a value from the drop-down list.');
|
||||||
$objValidation->setFormula1('"Item A,Item B,Item C"');
|
$validation->setFormula1('"Item A,Item B,Item C"');
|
||||||
```
|
```
|
||||||
|
|
||||||
When using a data validation list like above, make sure you put the list between " and " and that you split the items with a comma (,).
|
When using a data validation list like above, make sure you put the list between " and " and that you split the items with a comma (,).
|
||||||
|
|
||||||
It is important to remember that any string participating in an Excel formula is allowed to be maximum 255 characters (not bytes). This sets a limit on how many items you can have in the string "Item A,Item B,Item C". Therefore it is normally a better idea to type the item values directly in some cell range, say A1:A3, and instead use, say, $objValidation->setFormula1('Sheet!$A$1:$A$3');. Another benefit is that the item values themselves can contain the comma "," character itself.
|
It is important to remember that any string participating in an Excel formula is allowed to be maximum 255 characters (not bytes). This sets a limit on how many items you can have in the string "Item A,Item B,Item C". Therefore it is normally a better idea to type the item values directly in some cell range, say A1:A3, and instead use, say, $validation->setFormula1('Sheet!$A$1:$A$3');. Another benefit is that the item values themselves can contain the comma "," character itself.
|
||||||
|
|
||||||
If you need data validation on multiple cells, one can clone the ruleset:
|
If you need data validation on multiple cells, one can clone the ruleset:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$spreadsheet->getActiveSheet()->getCell('B8')->setDataValidation(clone $objValidation);
|
$spreadsheet->getActiveSheet()->getCell('B8')->setDataValidation(clone $validation);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Setting a column's width
|
## Setting a column's width
|
||||||
|
@ -1011,30 +1011,30 @@ $spreadsheet->getActiveSheet()->insertNewRowBefore(7, 2);
|
||||||
A drawing is always represented as a separate object, which can be added to a worksheet. Therefore, you must first instantiate a new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing, and assign its properties a meaningful value:
|
A drawing is always represented as a separate object, which can be added to a worksheet. Therefore, you must first instantiate a new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing, and assign its properties a meaningful value:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
|
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
|
||||||
$objDrawing->setName('Logo');
|
$drawing->setName('Logo');
|
||||||
$objDrawing->setDescription('Logo');
|
$drawing->setDescription('Logo');
|
||||||
$objDrawing->setPath('./images/officelogo.jpg');
|
$drawing->setPath('./images/officelogo.jpg');
|
||||||
$objDrawing->setHeight(36);
|
$drawing->setHeight(36);
|
||||||
```
|
```
|
||||||
|
|
||||||
To add the above drawing to the worksheet, use the following snippet of code. PhpSpreadsheet creates the link between the drawing and the worksheet:
|
To add the above drawing to the worksheet, use the following snippet of code. PhpSpreadsheet creates the link between the drawing and the worksheet:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objDrawing->setWorksheet($spreadsheet->getActiveSheet());
|
$drawing->setWorksheet($spreadsheet->getActiveSheet());
|
||||||
```
|
```
|
||||||
|
|
||||||
You can set numerous properties on a drawing, here are some examples:
|
You can set numerous properties on a drawing, here are some examples:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objDrawing->setName('Paid');
|
$drawing->setName('Paid');
|
||||||
$objDrawing->setDescription('Paid');
|
$drawing->setDescription('Paid');
|
||||||
$objDrawing->setPath('./images/paid.png');
|
$drawing->setPath('./images/paid.png');
|
||||||
$objDrawing->setCoordinates('B15');
|
$drawing->setCoordinates('B15');
|
||||||
$objDrawing->setOffsetX(110);
|
$drawing->setOffsetX(110);
|
||||||
$objDrawing->setRotation(25);
|
$drawing->setRotation(25);
|
||||||
$objDrawing->getShadow()->setVisible(true);
|
$drawing->getShadow()->setVisible(true);
|
||||||
$objDrawing->getShadow()->setDirection(45);
|
$drawing->getShadow()->setDirection(45);
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also add images created using GD functions without needing to save them to disk first as In-Memory drawings.
|
You can also add images created using GD functions without needing to save them to disk first as In-Memory drawings.
|
||||||
|
@ -1046,17 +1046,17 @@ $textColor = imagecolorallocate($gdImage, 255, 255, 255);
|
||||||
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
|
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
|
||||||
|
|
||||||
// Add the In-Memory image to a worksheet
|
// Add the In-Memory image to a worksheet
|
||||||
$objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing();
|
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing();
|
||||||
$objDrawing->setName('In-Memory image 1');
|
$drawing->setName('In-Memory image 1');
|
||||||
$objDrawing->setDescription('In-Memory image 1');
|
$drawing->setDescription('In-Memory image 1');
|
||||||
$objDrawing->setCoordinates('A1');
|
$drawing->setCoordinates('A1');
|
||||||
$objDrawing->setImageResource($gdImage);
|
$drawing->setImageResource($gdImage);
|
||||||
$objDrawing->setRenderingFunction(
|
$drawing->setRenderingFunction(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG
|
\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG
|
||||||
);
|
);
|
||||||
$objDrawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
|
$drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
|
||||||
$objDrawing->setHeight(36);
|
$drawing->setHeight(36);
|
||||||
$objDrawing->setWorksheet($spreadsheet->getActiveSheet());
|
$drawing->setWorksheet($spreadsheet->getActiveSheet());
|
||||||
```
|
```
|
||||||
|
|
||||||
## Reading Images from a worksheet
|
## Reading Images from a worksheet
|
||||||
|
@ -1108,14 +1108,14 @@ Adding rich text to a cell can be done using \PhpOffice\PhpSpreadsheet\RichText
|
||||||
> This invoice is *__payable within thirty days after the end of the month__* unless specified otherwise on the invoice.
|
> This invoice is *__payable within thirty days after the end of the month__* unless specified otherwise on the invoice.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objRichText = new \PhpOffice\PhpSpreadsheet\RichText();
|
$richText = new \PhpOffice\PhpSpreadsheet\RichText();
|
||||||
$objRichText->createText('This invoice is ');
|
$richText->createText('This invoice is ');
|
||||||
$objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
|
$payable = $richText->createTextRun('payable within thirty days after the end of the month');
|
||||||
$objPayable->getFont()->setBold(true);
|
$payable->getFont()->setBold(true);
|
||||||
$objPayable->getFont()->setItalic(true);
|
$payable->getFont()->setItalic(true);
|
||||||
$objPayable->getFont()->setColor( new \PhpOffice\PhpSpreadsheet\Style\Color( \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN ) );
|
$payable->getFont()->setColor( new \PhpOffice\PhpSpreadsheet\Style\Color( \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN ) );
|
||||||
$objRichText->createText(', unless specified otherwise on the invoice.');
|
$richText->createText(', unless specified otherwise on the invoice.');
|
||||||
$spreadsheet->getActiveSheet()->getCell('A18')->setValue($objRichText);
|
$spreadsheet->getActiveSheet()->getCell('A18')->setValue($richText);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Define a named range
|
## Define a named range
|
||||||
|
@ -1162,8 +1162,8 @@ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetm
|
||||||
header('Content-Disposition: attachment;filename="myfile.xlsx"');
|
header('Content-Disposition: attachment;filename="myfile.xlsx"');
|
||||||
header('Cache-Control: max-age=0');
|
header('Cache-Control: max-age=0');
|
||||||
|
|
||||||
$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||||
$objWriter->save('php://output');
|
$writer->save('php://output');
|
||||||
```
|
```
|
||||||
|
|
||||||
Example of a script redirecting an Xls file to the client's browser:
|
Example of a script redirecting an Xls file to the client's browser:
|
||||||
|
@ -1176,8 +1176,8 @@ header('Content-Type: application/vnd.ms-excel');
|
||||||
header('Content-Disposition: attachment;filename="myfile.xls"');
|
header('Content-Disposition: attachment;filename="myfile.xls"');
|
||||||
header('Cache-Control: max-age=0');
|
header('Cache-Control: max-age=0');
|
||||||
|
|
||||||
$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
|
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
|
||||||
$objWriter->save('php://output');
|
$writer->save('php://output');
|
||||||
```
|
```
|
||||||
|
|
||||||
**Caution:**
|
**Caution:**
|
||||||
|
@ -1214,14 +1214,14 @@ $textColor = imagecolorallocate($gdImage, 255, 255, 255);
|
||||||
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
|
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
|
||||||
|
|
||||||
// Add a drawing to the worksheet
|
// Add a drawing to the worksheet
|
||||||
$objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing();
|
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing();
|
||||||
$objDrawing->setName('Sample image');
|
$drawing->setName('Sample image');
|
||||||
$objDrawing->setDescription('Sample image');
|
$drawing->setDescription('Sample image');
|
||||||
$objDrawing->setImageResource($gdImage);
|
$drawing->setImageResource($gdImage);
|
||||||
$objDrawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG);
|
$drawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG);
|
||||||
$objDrawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
|
$drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
|
||||||
$objDrawing->setHeight(36);
|
$drawing->setHeight(36);
|
||||||
$objDrawing->setWorksheet($spreadsheet->getActiveSheet());
|
$drawing->setWorksheet($spreadsheet->getActiveSheet());
|
||||||
```
|
```
|
||||||
|
|
||||||
## Setting worksheet zoom level
|
## Setting worksheet zoom level
|
||||||
|
@ -1239,7 +1239,7 @@ Note that zoom level should be in range 10 - 400.
|
||||||
Sometimes you want to set a color for sheet tab. For example you can have a red sheet tab:
|
Sometimes you want to set a color for sheet tab. For example you can have a red sheet tab:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWorksheet->getTabColor()->setRGB('FF0000');
|
$worksheet->getTabColor()->setRGB('FF0000');
|
||||||
```
|
```
|
||||||
|
|
||||||
## Creating worksheets in a workbook
|
## Creating worksheets in a workbook
|
||||||
|
@ -1247,8 +1247,8 @@ $objWorksheet->getTabColor()->setRGB('FF0000');
|
||||||
If you need to create more worksheets in the workbook, here is how:
|
If you need to create more worksheets in the workbook, here is how:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$objWorksheet1 = $spreadsheet->createSheet();
|
$worksheet1 = $spreadsheet->createSheet();
|
||||||
$objWorksheet1->setTitle('Another sheet');
|
$worksheet1->setTitle('Another sheet');
|
||||||
```
|
```
|
||||||
|
|
||||||
Think of createSheet() as the "Insert sheet" button in Excel. When you hit that button a new sheet is appended to the existing collection of worksheets in the workbook.
|
Think of createSheet() as the "Insert sheet" button in Excel. When you hit that button a new sheet is appended to the existing collection of worksheets in the workbook.
|
||||||
|
|
Loading…
Reference in New Issue