Member-only story

Reading Excel Files Without Packages in Laravel: A Step-by-Step Guide

ArjunAmrutiya
4 min readNov 14, 2024

--

Introduction:
Reading Excel files in Laravel usually involves packages like PhpSpreadsheet or Laravel Excel. But what if you want to keep your application lean, reduce dependencies, or gain control over the parsing process? This guide will walk you through reading Excel files without using any external packages in Laravel. We’ll parse the raw file and extract the data, making it a simple and efficient solution for basic use cases.

Prerequisites:
To follow along, you should have a basic understanding of:

  • Laravel framework
  • PHP file handling and XML parsing basics

Excel File Structure:
Excel files (XLSX) are essentially compressed ZIP files with a specific structure.
Each XLSX file contains:

  1. Shared Strings (xl/sharedStrings.xml):-Stores all unique strings in the file, referenced by index.
  2. Worksheet Files (xl/worksheets/sheet1.xml, etc.): Contains cell data and references to shared strings.

Step-by-Step Guide

Step 1: Extracting the Contents:
Since XLSX files are ZIP archives, we can extract them using PHP’s ZipArchive class.

--

--

ArjunAmrutiya
ArjunAmrutiya

Written by ArjunAmrutiya

👋 Hey there! I'm Arjun Amrutiya, a passionate web developer and blogger who loves all things PHP, Laravel and Vue.js. Welcome to my Medium account!

No responses yet