自定义起始单元格
匿名 · 更新于 2021/6/28
默认起始单元格是A1。WithCustomStartCell在导出类中实现关注点允许您指定自定义起始单元格。
namespace App\Exports;
use App</span>Invoice;
use Maatwebsite</span>Excel</span>Concerns</span>FromCollection;
use Maatwebsite</span>Excel</span>Concerns</span>WithCustomStartCell;
class InvoicesExport implements FromCollection, WithCustomStartCell
{
public function collection()
{
return Invoice::all();
}
<span class="token keyword" style="color: rgb(204, 153, 205); font-style: italic !important;">public</span> <span class="token keyword" style="color: rgb(204, 153, 205); font-style: italic !important;">function</span> <span class="token function" style="color: rgb(240, 141, 73);">startCell</span><span class="token punctuation" style="color: rgb(204, 204, 204);">(</span><span class="token punctuation" style="color: rgb(204, 204, 204);">)</span><span class="token punctuation" style="color: rgb(204, 204, 204);">:</span> string
<span class="token punctuation" style="color: rgb(204, 204, 204);">{</span>
<span class="token keyword" style="color: rgb(204, 153, 205); font-style: italic !important;">return</span> <span class="token single-quoted-string string" style="color: rgb(126, 198, 153);">'B2'</span><span class="token punctuation" style="color: rgb(204, 204, 204);">;</span>
<span class="token punctuation" style="color: rgb(204, 204, 204);">}</span>
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
WithCustomStartCell仅支持FromCollection导出。
