Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
laravel maatwebsite excel更改工作表方向_Laravel_Export To Excel_Maatwebsite Excel - Fatal编程技术网

laravel maatwebsite excel更改工作表方向

laravel maatwebsite excel更改工作表方向,laravel,export-to-excel,maatwebsite-excel,Laravel,Export To Excel,Maatwebsite Excel,如何更改laravel maatwebsite excel包中的工作表方向? 我想从左改右 A B C D 致: 这是我的代码: $row = $this->userRepository->getById(1); $data = $row; Excel::create('test', function ($excel) use($data) { $excel->sheet('sheet', function

如何更改laravel maatwebsite excel包中的工作表方向? 我想从左改右

A B C D
致:

这是我的代码:

   $row =  $this->userRepository->getById(1);

        $data = $row;
        Excel::create('test', function ($excel) use($data) {

            $excel->sheet('sheet', function ($sheet) use($data) {
                $sheet->fromArray($data, null, 'A1', false, false);
                $sheet->row(1, function($row) {
                });

            });
        })->store('xlsx', storage_path('excel/exports'))->download('xlsx');

您只需在行中使用
foreach
,并在提交到excel之前使用
array\u reverse($row)
,因为laravel excel是基于phpExcel制作的,所以您可以对
$excel
对象或
$sheet
对象使用本机phpExcel方法

以下是更改图纸方向的代码

 $excel->sheet('sheet', function ($sheet) use($data) {
                $sheet->->setRightToLeft(true);
                $sheet->fromArray($data, null, 'A1', false, false);
                $sheet->row(1, function($row) {
                });

分享你的代码到目前为止你都尝试了些什么?@kunal好的,我把这个问题补充到这里是maatwebsite@kunal的完整文档是的,我知道。但我找不到任何方向选项。不,我认为maatwebsite excel没有提供任何函数来更改方向,但您可以在垂直或水平方向上更改excel工作表的设置。虽然此代码可能会回答这个问题,但最好包含一些上下文,解释它是如何工作的以及何时使用它。从长远来看,只使用代码的答案是没有用的。在你回答+1表示这一点时,我使用了你的代码将近3年。但是,您在setRightToLeft中使用了双->->。。。我想编辑is,但它说:“建议的编辑队列已满”。无论如何谢谢你
 $excel->sheet('sheet', function ($sheet) use($data) {
                $sheet->->setRightToLeft(true);
                $sheet->fromArray($data, null, 'A1', false, false);
                $sheet->row(1, function($row) {
                });
class TractsExport implements FromCollection,WithEvents
{

    public function registerEvents(): array
    {
        return [

            BeforeSheet::class  =>function(BeforeSheet $event){
                $event->getDelegate()->setRightToLeft(true);
            }
        ];
    }
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        retutn Tract::all();
}