TradeExport.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Admin\Exports\Caiqing;
  3. use App\Admin\Exports\RowExport;
  4. use Illuminate\Support\Collection;
  5. class TradeExport extends RowExport
  6. {
  7. public $name = '';
  8. function __construct($name){
  9. $this->name = $name;
  10. }
  11. /**
  12. * 设置标题,返回标题数组
  13. * @return array
  14. */
  15. public function headings(): array
  16. {
  17. return [
  18. '行业',
  19. '序号',
  20. '需求人数(人)',
  21. '所占比重(%)'
  22. ];
  23. }
  24. /**
  25. * 处理行数据
  26. * @param Model $row
  27. * @return array
  28. */
  29. public function map($row): array
  30. {
  31. $result = [];
  32. foreach ($row as $k => $v) {
  33. if ($k == 'rate') {
  34. $result[$k] = $v.'%';
  35. } else {
  36. $result[$k] = $v.'';
  37. }
  38. }
  39. return $result;
  40. }
  41. /**
  42. * 设置文件名
  43. * @return string
  44. */
  45. public function getFilename(): string
  46. {
  47. return $this->name.".xlsx";
  48. }
  49. /**
  50. * 格式化指定列.
  51. * 只有在需要的时候设置,例如在身份证不要显示科学计数时设定列格式:['A'=>NumberFormat::FORMAT_NUMBER]
  52. * @return array
  53. */
  54. public function columnFormats(): array
  55. {
  56. return [
  57. ];
  58. }
  59. }