nebbo.o/laravel-sheet-parser

A Laravel package to parse data from public Google Sheets and CSV files using a unified interface.

Maintainers

Package info

github.com/nebojsha-mitikj/laravel-sheet-parser

pkg:composer/nebbo.o/laravel-sheet-parser

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

v2.0.1 2025-10-01 18:29 UTC

This package is auto-updated.

Last update: 2026-03-01 00:47:38 UTC


README

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

Method Description
toArray(): array Returns the data as an array of associative arrays (using headers as keys).
toJson(): string Returns the data as JSON.
toCollection(): \Illuminate\Support\Collection Returns the data as a Laravel collection.
headers(): array Returns the headers row.
count(): int Returns the number of data rows (excluding headers).
row(int $index): ?array Returns a specific row by index.
column(string $header): array Returns all values from a specific column.
first(): ?array Returns the first row of data.
last(): ?array Returns the last row of data.
hasHeader(string $header): bool Checks if a given header exists.

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

  • PHP 8.1+
  • Laravel 10, 11, or 12

License

This package is open-sourced software licensed under the MIT license