labelworx/excel-converter

快速将 XLSX、XLS 或以逗号分隔的文件(如 CSV、TSV、分号分隔、管道分隔或您选择的任何自定义分隔符)转换为分隔符文件。

1.4.4 2024-07-18 13:47 UTC

This package is auto-updated.

Last update: 2024-09-18 14:06:55 UTC


README

本包允许您快速将 XLSX、XLS 或以逗号分隔的文件(如 CSV、TSV、分号分隔、管道分隔或您选择的任何自定义分隔符)转换为分隔符文件。

安装

使用 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');

Laravel 使用

对于 Laravel 用户,可以选择使用 门面

use LabelWorx\ExcelConverter\Facades\ExcelConverter;

ExcelConverter::source('path/to/input.xls')->toCSV('path/to/output.csv');

贡献

欢迎提交拉取请求。对于重大更改,请先打开一个问题来讨论您希望进行哪些更改。

请确保根据需要更新测试。

许可证

MIT