Using the Spout Library:
Spout is a lightweight PHP library for reading and writing spreadsheet files, including Excel files. To convert an Excel file into table columns using Spout, you can utilize the Spout library. Here's an example:
//...
require 'vendor/autoload.php';
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
// Create a reader instance
$reader = ReaderEntityFactory::createXLSXReader();
// Open the Excel file
$reader->open('example.xlsx');
// Get the first sheet
$reader->open('example.xlsx');
$sheet = $reader->getSheetIterator()->current();
// Iterate through each row
foreach ($sheet->getRowIterator() as $row) {
$rowValues = $row->toArray();
foreach ($rowValues as $column => $value) {
echo "Column $column: $value<br>";
}
}
//...
In this example, we first require the Spout library. We create a reader instance using `ReaderEntityFactory::createXLSXReader()`. We then open the Excel file using `$reader->open()`. We retrieve the first sheet using `$reader->getSheetIterator()->current()`. We iterate through each row and retrieve the values using `$row->toArray()`. Finally, we display the column values.
These examples demonstrate techniques for converting Excel files into table columns using PHP 8. The PhpSpreadsheet and Spout libraries provide powerful features for working with Excel files, allowing you to extract data and transform it into table columns for further processing. Experiment with these examples and integrate them into your web development projects to efficiently handle Excel file conversions.