rudi97277/export-db
最新稳定版本:v1.0.2
Composer 安装命令:
composer require rudi97277/export-db
包简介
Export data to XLSX or CSV formats from database queries or functions
README 文档
README
install this package using
composer require rudi97277/export-db
How to Use This Package
-
Run the Migration
- Execute the migration to create the necessary database structure.
-
Table Creation
- A new table named
export_configswill be generated.
- A new table named
-
Insert Data
- Insert new data into the
export_configstable to create a new report.
- Insert new data into the
-
Create a New Route
- Define a new route that creates an instance of the
Rudi9277/ExportDb/GenerateReportclass and calls thegeneratefunction. Pass therequestas a parameter.
Example route definition:
Route::get('export', function () { return Rudi9277\ExportDb\GenerateReport::generate(request()); });
- Define a new route that creates an instance of the
-
Run Symlink
- If you never run a symlink command before, please run it
php artisan storage:link
- If you never run a symlink command before, please run it
Note:
- Available
export_typearexlsxandcsv. - You can create a new module in the database.
Table columns:
-
module: The name of the module that will be exported.
-
title: The title of the sheet in the Excel that will be generated.
-
query: The query that will be used to generate the Excel.
-
formatter: JSON object that will help format the data the way you want.
Example:
[ { "name": "Product", "value": "--- {product_name} ----" } ]Note:
- The
"name"key is the header in the Excel that will be generated. {product_name}is the column name in the SQL query result.
- The
-
validator: JSON object that will help to validate the required data for the query. The validator is from Laravel Validator.
Example:
{ "name": "required|string" } -
default: A default JSON object that sets what the default value of the validator in No. 5 is.
Example:
{ "name": null } -
To style the data, you can use ExportDTO to pass callable function to the generator like this example
Route::get('export', function () { $style = function (Worksheet $sheet) { return [ 'A' => [ 'alignment' => [ 'horizontal' => Alignment::HORIZONTAL_CENTER, ], ], ]; }; $reg = function () { return [ AfterSheet::class => function ($event) { $sheet = $event->sheet->getDelegate(); $sheet->getStyle('B:B')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); }, ]; }; $dto = new ExportDTO($func, $style); return Rudi97277\ExportDb\GenerateReport::generate(request(),$dto); });
please check Laravel Excel how to use the styles
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-03