Laravel-excel: [QUESTION] how do i set custom headers when downloading?

Created on 5 Jul 2016  ·  7Comments  ·  Source: Maatwebsite/Laravel-Excel

as stated above.. is it possible to set custom response headers ?

All 7 comments

Second param of ->export(fileType, [headers]) accepts an array of headers

Any example please.
Thanks.

Hello,

I've set second param as array for export function. But not working. Please see my code bellow.
Please help me. Thanks.

Source:
public function example(){
$action = new ActionRepository();
$items = $action->all('ev_no asc');
Excel::create('items', function($excel) use($items) {
$excel->sheet('ExportFile', function($sheet) use($items) {
$sheet->fromArray($items, null, 'A1', false, false);
});
})->export('csv', ['イベントNo', 'メッセージ', '商品分類コード', '登録単位', '設定値', 'タイミング']);
}

Result:
"1001","最終購入から[設定値]ヶ月以上経過してます。状況を把握してください。","","月","12"
"1101","最終購入から[設定値]年経過しました。メンテナンスを勧めてみませんか?","","年","3"
"1102","最終購入から[設定値]年経過しました。メンテナンスを勧めてみませんか?","","年","3"
"2001","次の活動予定日が入力されていません。","","",""
"2101","次の活動予定日から[設定値]日以上経過しています。完了している場合は完了日を入力してください。","","日","2"
"3001","来月、決算月を迎える顧客です。","","日","10"
"3102","来月、設立1周年を迎える顧客です。","","周年","1"
"3103","来月、設立3周年を迎える顧客です","","周年","3"
"3201","来月、設立5×n周年を迎える顧客です。","","周年","5"
"3301","顧客情報の更新タイミングです。","","日","1"

How can I do this with version 3.1?

@andreshg112 from the docs: You can customize the download headers with the optional 3rd parameter $headers (https://docs.laravel-excel.com/3.1/exports/export-formats.html#export-formats)

@patrickbrouwers, thank you! What about if I use IlluminateContracts\Support\Responsable? My controller looks like this:
imagen

@andreshg112 that's not supported on the current release yet. Next release will have ability to set the headers inside the export class.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

contifico picture contifico  ·  3Comments

lucatamtam picture lucatamtam  ·  3Comments

bahmanyaghoobi picture bahmanyaghoobi  ·  3Comments

gamevnlc picture gamevnlc  ·  3Comments

pamekar picture pamekar  ·  3Comments