This package allows you to quickly convert XLSX, XLS or delimited files such as CSV, TSV, Semi Colon, Pipe Delimited or files with any bespoke delimiter of your choosing to a delimited file.
Require the package using composer:
composer require labelworx/excel-converter
use LabelWorx\ExcelConverter\ExcelConverter;
$excel = new ExcelConverter();
// Simple Conversions
$excel->source('path/to/input.xls')->toCSV('path/to/output.csv');
$excel->source('path/to/input.xlsx')->toTSV('path/to/output.tsv');
$excel->source('path/to/input.csv')->toTSV('path/to/output.tsv');
$excel->source('path/to/input.tsv')->toCSV('path/to/output.csv');
// Converts Pipe delimited file to Semi-Colon delimited file by passing delimiters
$excel->source('path/to/input.txt', '|')->to('path/to/output.txt', ';');
// For Excel source files you can specify a worksheet by name or number
$excel->source('path/to/input.xls')->worksheet('Sheet 2')->toCSV('path/to/output.csv');
$excel->source('path/to/input.xlsx')->worksheet(2)->toTSV('path/to/output.tsv');
// For Excel source files you can also specify an export date format
$excel->source('path/to/input.xls')->exportDateFormat('d/m/Y')->toCSV('path/to/output.csv');
$excel->source('path/to/input.xlsx')->exportDateFormat('d/m/Y')->toTSV('path/to/output.tsv');
For Laravel users there is the option of using a Facade
.
use LabelWorx\ExcelConverter\Facades\ExcelConverter;
ExcelConverter::source('path/to/input.xls')->toCSV('path/to/output.csv');
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.