IndustryExport.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Admin\Exports\Caiqing;
  3. use App\Admin\Exports\RowExport;
  4. use Illuminate\Support\Collection;
  5. class IndustryExport extends RowExport
  6. {
  7. public $name = '';
  8. function __construct($name)
  9. {
  10. $this->name = $name;
  11. }
  12. /**
  13. * 设置标题,返回标题数组
  14. * @return array
  15. */
  16. public function headings(): array
  17. {
  18. return [
  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. }