-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
861 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
samples/Reader/21_Reader_CSV_Long_Integers_with_String_Value_Binder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use PhpOffice\PhpSpreadsheet\Cell\Cell; | ||
use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder; | ||
use PhpOffice\PhpSpreadsheet\IOFactory; | ||
|
||
require __DIR__ . '/../Header.php'; | ||
|
||
Cell::setValueBinder(new StringValueBinder()); | ||
|
||
$inputFileType = 'Csv'; | ||
$inputFileName = __DIR__ . '/sampleData/longIntegers.csv'; | ||
|
||
$reader = IOFactory::createReader($inputFileType); | ||
$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' into WorkSheet #1 using IOFactory with a defined reader type of ' . $inputFileType); | ||
|
||
$spreadsheet = $reader->load($inputFileName); | ||
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME)); | ||
|
||
$helper->log($spreadsheet->getSheetCount() . ' worksheet' . (($spreadsheet->getSheetCount() == 1) ? '' : 's') . ' loaded'); | ||
$loadedSheetNames = $spreadsheet->getSheetNames(); | ||
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) { | ||
$helper->log('<b>Worksheet #' . $sheetIndex . ' -> ' . $loadedSheetName . ' (Formatted)</b>'); | ||
$spreadsheet->setActiveSheetIndexByName($loadedSheetName); | ||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); | ||
var_dump($sheetData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"Column 1","Column 2" | ||
123456789012345678901234,234567890123456789012345 | ||
345678901234567890123456,456789012345678901234567 | ||
567890123456789012345678,678901234567890123456789 | ||
789012345678901234567890,890123456789012345678901 | ||
901234567890123456789012,012345678901234567890123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheet\Cell; | ||
|
||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; | ||
|
||
class StringValueBinder implements IValueBinder | ||
{ | ||
/** | ||
* Bind value to a cell. | ||
* | ||
* @param Cell $cell Cell to bind value to | ||
* @param mixed $value Value to bind in cell | ||
* | ||
* @throws \PhpOffice\PhpSpreadsheet\Exception | ||
* | ||
* @return bool | ||
*/ | ||
public function bindValue(Cell $cell, $value) | ||
{ | ||
// sanitize UTF-8 strings | ||
if (is_string($value)) { | ||
$value = StringHelper::sanitizeUTF8($value); | ||
} | ||
|
||
$cell->setValueExplicit((string) $value, DataType::TYPE_STRING); | ||
|
||
// Done! | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.