从刀片视图导出到带有字体大小和样式的Excel

时间:2019-03-22 07:20:56

标签: excel laravel eloquent maatwebsite-excel

我正在使用Maatwebsite / Excel将Blade视图导出到excel,但是当我将其导出到excel时,字体大小不会生效,也不会使其居中。

如果在maatwebiste / excel中不可能,是否还有其他报告服务,例如laravel的RDLC报告

我的观点

<html>
<head>
<title>asdf</title>
</head>

<body>
<table border="1" cellpadding="0px" cellspacing="0px" width="100%">
    <thead>
    <tr>
        <td width="100%" colspan="12" align="center" style="text-align: 
center;font-size:50pt">Should be large and in center</td>
    </tr>
    <tr>
        <td>id</td>
    <td>quantity</td>
    <td>units_id</td>
    <td>description</td>
    <td>requster</td>
    <td>checker</td>
    <td>approver</td>
    <td>created_at</td>
    <td>updated_at</td>
    <td>remarks</td>
    <td>request_number</td>
    <td>steps</td>
    </tr>
    </thead>
 <tbody>
 @foreach($posts as $post)
 <tr>
    <td>{{$post->id}}</td>
    <td>{{$post->quantity}}</td>
    <td>{{$post->units_id}}</td>
    <td>{{$post->description}}</td>
    <td>{{$post->requster}}</td>
    <td>{{$post->checker}}</td>
    <td>{{$post->approver}}</td>
    <td>{{$post->created_at}}</td>
    <td>{{$post->updated_at}}</td>
    <td>{{$post->remarks}}</td>
    <td>{{$post->request_number}}</td>
    <td>{{$post->steps}}</td>
</tr>
    @endforeach
</tbody>
</table>
</body>
</html>

我的控制器

    public function export()
{
    return Excel::download(new UsersExport, 'posts.xlsx');
}

还有我的导出控制器

class UsersExport implements FromView
{
public function view(): View
{
    return view('exporting', [
        'posts' => Procurment_request::all()
    ]);
}
}

我的看法 enter image description here

我导出的Excel文件 enter image description here

预先感谢

1 个答案:

答案 0 :(得分:0)

您需要自行配置。

看看有关如何format Columns的文档。

class InvoicesExport implements WithColumnFormatting, WithMapping
    {
        public function map($invoice): array
        {
            return [
               $invoice->invoice_number,
               Date::dateTimeToExcel($invoice->created_at),
               $invoice->total
            ];
         }

    /**
    * @return array
    */
    public function columnFormats(): array
    {
        return [
            'B' => NumberFormat::FORMAT_DATE_DDMMYYYY,
            'C' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE,
        ];
     }
}