こんにちは、
バージョン3.1で生成されたExcelファイルを添付するにはどうすればよいですか?
以前のバージョン(v.2)では、「-> download()」なしでcreateメソッドを使用できました。
私はこの方法で試していますが、機能しません:
$filename = 'text.xlsx';
$attachment = Excel::download(new TestExport(), $filename);
\Mail::to('[email protected]')->send(new SendMail($attachment));
# Inside SendMail.php
public function __construct($attachment)
{
$this->attachment = $attachment;
}
public function build()
{
$mail = $this->from('[email protected]')
->subject('test attachment')
->markdown('emails.test_mail')
->attach($this->attachment);
return $mail;
}
まったく同じ質問があります。
ファイル内のexport()メソッドをprotectedからpublicに変更するソリューションを見つけました。
maatwebsite \ excel \ src \ Excel.php
行:166
このように、コードは次のようになります。
「」
$ attachment = Excel :: export(new TestExport()、$ filename);
[...]
$ mail = $ this-> from('[email protected] ')
-> subject( 'テスト添付ファイル')
-> markdown( 'emails.test_mail')
-> attach($ this-> attach 、、 ['as' => $ filename]);
「」
Excelクラスとその保護されたメソッドを変更せずに機能させるための解決策を見つけました。 あなたは呼び出すことができますgetFile()
からExcel::download(/**/)
。 コードは次のようになります。
public function build()
{
return $this->markdown('emails.report')
->attach(
Excel::download(
new AuditReport($this->audit),
'report.xlsx'
)->getFile(), ['as' => 'report.xlsx']
);
}
Excel::download()
はBinaryFileResponse
を返すため、直接機能しませんが、ファイルを取得できます。
お役に立てば幸いです😃
Excelクラスとその保護されたメソッドを変更せずに機能させるための解決策を見つけました。 あなたは呼び出すことができます
getFile()
からExcel::download(/**/)
。 コードは次のようになります。public function build() { return $this->markdown('emails.report') ->attach( Excel::download( new AuditReport($this->audit), 'report.xlsx' )->getFile(), ['as' => 'report.xlsx'] ); }
Excel::download()
はBinaryFileResponse
を返すため、直接機能しませんが、ファイルを取得できます。それが役に立てば幸い
ただし、ファイルがディスクに書き込まれるときは、サーバーのtmpディレクトリに注意してください。
エクスポートはパブリックメソッドである必要があります。
助け合ってくれてありがとう! 👍
ファイルをダウンロード/作成せずにそれを行う方法は次のとおりです。
use Maatwebsite\Excel\Excel as BaseExcel;
use Maatwebsite\Excel\Facades\Excel;
...
$filename = "{$this->po->po_memo}.xlsx";
$attachment = Excel::raw(new PurchaseOrderLinesExport($this->po), BaseExcel::XLSX);
$subject = "Purchase Order Invoice"
return $this->from($this->po->employee->email)
->subject($subject)
->view('emails.pom.send')
->text('emails.pom.send')
->attachData($attachment, $filename);
Excelクラスとその保護されたメソッドを変更せずに機能させるための解決策を見つけました。 あなたは呼び出すことができます
getFile()
からExcel::download(/**/)
。 コードは次のようになります。public function build() { return $this->markdown('emails.report') ->attach( Excel::download( new AuditReport($this->audit), 'report.xlsx' )->getFile(), ['as' => 'report.xlsx'] ); }
Excel::download()
はBinaryFileResponse
を返すため、直接機能しませんが、ファイルを取得できます。それがスマイリーに役立つことを願っています
これをありがとう、それは私のために働いた。
use Maatwebsite\Excel\Excel as BaseExcel; use Maatwebsite\Excel\Facades\Excel; ... $filename = "{$this->po->po_memo}.xlsx"; $attachment = Excel::raw(new PurchaseOrderLinesExport($this->po), BaseExcel::XLSX);
どうもありがとう。 それは私のために働いています
最も参考になるコメント
Excelクラスとその保護されたメソッドを変更せずに機能させるための解決策を見つけました。 あなたは呼び出すことができます
getFile()
からExcel::download(/**/)
。 コードは次のようになります。Excel::download()
はBinaryFileResponse
を返すため、直接機能しませんが、ファイルを取得できます。お役に立てば幸いです😃