rudi97277/export-db 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Run the Migration

    • Execute the migration to create the necessary database structure.
  2. Table Creation

    • A new table named export_configs will be generated.
  3. Insert Data

    • Insert new data into the export_configs table to create a new report.
  4. Create a New Route

    • Define a new route that creates an instance of the Rudi9277/ExportDb/GenerateReport class and calls the generate function. Pass the request as a parameter.

    Example route definition:

    Route::get('export', function () {
        return Rudi9277\ExportDb\GenerateReport::generate(request());
    });
  5. Run Symlink

    • If you never run a symlink command before, please run it php artisan storage:link

Note:

  • Available export_type are xlsx and csv.
  • You can create a new module in the database.

Table columns:

  1. module: The name of the module that will be exported.

  2. title: The title of the sheet in the Excel that will be generated.

  3. query: The query that will be used to generate the Excel.

  4. 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.
  5. validator: JSON object that will help to validate the required data for the query. The validator is from Laravel Validator.

    Example:

    {
      "name": "required|string"
    }
  6. default: A default JSON object that sets what the default value of the validator in No. 5 is.

    Example:

    {
      "name": null
    }
  7. 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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-03