laravel-sheet-parser maintained by nebbo.o
Description
A Laravel package to parse data from public Google Sheets and CSV files using a unified interface.
Author
Last update
2025/10/01 21:14
(dev-main)
License
Downloads
3
Laravel Sheet Parser 🚀
A Laravel package to parse data from CSV files and public Google Sheets using a unified interface.
Features
- Parse CSV files or public Google Sheets seamlessly.
- Consistent API for both data sources.
- Convert to arrays, JSON, or Laravel collections.
- Retrieve rows, columns, headers, or specific data points.
Installation
Require the package via Composer:
composer require nebbo.o/laravel-sheet-parser
Usage
1. Parsing CSV files
use NebboO\LaravelSheetParser\SheetParser;
$parser = SheetParser::fromCsv(storage_path('data/example.csv'));
$data = $parser->toArray(); // Convert to array
$json = $parser->toJson(); // Convert to JSON
$collection = $parser->toCollection(); // Convert to collection
2. Parsing Google Sheets
Make sure the sheet is publicly accessible (Anyone with the link can view).
use NebboO\LaravelSheetParser\SheetParser;
$url = 'https://docs.google.com/spreadsheets/d/your-sheet-id/edit?usp=sharing';
$parser = SheetParser::fromGoogleSheet($url);
$data = $parser->toArray(); // Convert to array
$json = $parser->toJson(); // Convert to JSON
$collection = $parser->toCollection(); // Convert to collection
API Reference
Both CsvParser and GoogleSheetParser implement the same ParserInterface.
Methods
Error Handling
The package provides custom exceptions you can catch to handle errors gracefully:
-
FileNotFoundException– CSV file does not exist. -
FileNotReadableException– CSV file cannot be read. -
InvalidFileTypeException– File is not a CSV. -
InvalidGoogleSheetUrlException– Invalid or missing Google Sheet URL. -
GoogleSheetDownloadException– Failed to fetch or parse Google Sheet data.
Requirements
PHP8.1+Laravel10, 11, or 12
License
This package is open-sourced software licensed under the MIT license