tbcd / excel-utils
轻松创建 Excel 工作表、电子表格和文件的方法
1.1.1
2023-08-05 16:42 UTC
Requires
- php: >=8.1.0
- ext-ctype: *
- ext-iconv: *
- phpoffice/phpspreadsheet: ^1.19
- symfony/filesystem: ^6.0
Requires (Dev)
- phpunit/phpunit: ^9.5|^10.0
This package is auto-updated.
Last update: 2024-09-05 19:09:44 UTC
README
此库可轻松创建 Excel 工作表、电子表格和文件。
用法
- 如果有容器,请从容器中注入服务,或者创建它
private ExcelFileFactory $excelFileFactor;
public function __construct(ExcelFileFactory $excelFileFactory)
{
$this->excelFileFactory = $excelFileFactory;
}
$excelFileFactory = new ExcelFileFactory($spreadsheetFactory);
- 使用您的数据创建文件
$data = [
[
'column1' => 'row1',
'column2' => 'row1',
'column3' => 'row1'
],
[
'column1' => 'row2',
'column2' => 'row2',
'column3' => 'row2'
]
];
$filePath = $fileFactory->createFileWithData(new WorksheetData($data, 'my-sheet-name'), 'my_file.xlsx');
- 然后得到以下结果
