PHP code example of linio / spreadsheet-parser

1. Go to this page and download the library: Download linio/spreadsheet-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

linio / spreadsheet-parser example snippets




use Linio\Component\SpreadsheetParser\Spreadsheet;

$spreadsheet = new Spreadsheet('/folder/file.csv');

$columnNames = $spreadsheet->getColumnNames();
$data = $spreadsheet->getData();



$container['spreadsheet.parser'] = function() {
    return new SpreadsheetParserService();
}

$spreadsheet = $container['spreadsheet.parser']->parseSpreadsheet($filePath, $fileType, $options);
$columnNames = $spreadsheet->getColumnNames();
$data = $spreadsheet->getData();



    use Linio\Component\SpreadsheetParser\Spreadsheet;
    use Linio\Component\SpreadsheetParser\Exception\FileNotFoundException;
    use Linio\Component\SpreadsheetParser\Exception\InvalidFileTypeException;
    use Linio\Component\SpreadsheetParser\Parser\CsvParser;

    /**
     * @param $filePath
     * @param string $fileType
     * @param array $options
     *
     * @throws FileNotFoundException
     * @throws InvalidFileTypeException
     */
    public function __construct($filePath, $fileType = null, array $options = []);

    $spreadsheet = new Spreadsheet('/folder/file.txt', Spreadsheet::TYPE_CSV, [CsvParser::OPTION_DELIMITER => ';']);




     /**
     * @return void
     */
    public function open();




    /**
     * @return array|false
     */
    public function getColumnNames();

    $columnNames = $spreadsheet->getColumnNames();




    /**
     * @param int $numRows
     *
     * @return array
     */
    public function getData($numRows = 0);

    $dataWholeFile = $spreadsheet->getData();

    $dataFirst5Lines = $spreadsheet->getData(5);




     /**
     * @return void
     */
    public function close();

    $spreadsheet->close();