×ðÁú¿­Ê±¹ÙÍøµÇ¼

laravel excelÉèÖÃÍ·

ÔÚʹÓÃlaravel excelʱ £¬ÉèÖñíÍ·ÊÇÒ»¸öºÜÊÇÖ÷ÒªµÄʹÃü¡£±íͷͨ³£ÓÃÓÚÖ¸¶¨°üÀ¨ÔÚexcelÎļþÖеÄÁеÄÃû³Æ £¬²¢ÇÒʹµÃÊý¾Ý¼¯Ô½·¢Ò×ÓÚÃ÷È·ºÍÆÊÎö¡£ÔÚÕâƪÎÄÕÂÖÐ £¬ÎÒÃǽ«»áÏÈÈÝÔõÑùÉèÖÃÍ·¡£

Laravel ExcelÊÇÒ»¸ö¿ªÔ´µÄ¹¤¾ß £¬ÎÒÃÇ¿ÉÒÔʹÓÃËüÀ´¶ÁÈ¡¡¢²Ù×÷ºÍµ¼³öExcelÎļþ £¬ËüÌṩÁËÒ»ÖÖ¼òÆÓ¡¢ÓÅÑŵÄÒªÁìÀ´´¦ÀíExcelÎļþ £¬²¢ÇÒʹµÃExcelÎļþµÄÌìÉúÀú³ÌÔ½·¢ÇáËÉ¡£

Laravel Excelͨ¹ýÉèÖñíÍ·À´¾ÙÐÐÊý¾Ýµ¼³ö¡£ÔÚÎÒÃÇÌìÉúExcelÎļþ֮ǰ £¬ÎÒÃÇÐèÒª½ç˵ExcelÎļþµÄ±íÍ· £¬Õâ¸öÀú³Ìͨ³£±»³ÆΪ½ç˵ÎÊÌâÐС£

ÏÂÃæ¾ÍÊÇÉèÖñíÍ·µÄһЩҪÁì £¬ÈÃÎÒÃÇ×îÏÈ°É£¡

ʹÓÃwithHeadings()ÒªÁì

withHeadings()ÒªÁìÊÇLaravel ExcelÌṩµÄÒ»¸öÄÚÖÃÒªÁì £¬ËüÔÊÐíÎÒÃǽç˵±íÍ·¡£Õâ¸öÒªÁì½ÓÊÜÒ»¸öÊý×é×÷Ϊ²ÎÊý £¬Êý×éµÄÿ¸öÔªËض¼ÊÇÒ»¸ö±íÍ·µ¥Î»¸ñµÄÖµ¡£

ʾÀý´úÂ룺

use MaatwebsiteExcelFacadesExcel;

Excel::create('my_excel_file', function($excel) {
    $excel->sheet('Sheet 1', function($sheet) {
        $header = ['Name', 'Email', 'Phone'];
        $data = [
            ['John Doe', 'johndoe@gmail.com', '123-456-7890'],
            ['Jane Doe', 'janedoe@gmail.com', '123-456-7890'],
            ['Bob Smith', 'bobsmith@gmail.com', '123-456-7890']
        ];

        $sheet->with($data)->withHeadings($header);
    });
})->download('xlsx');

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öʾÀýÖÐ £¬ÎÒÃǽç˵ÁËÒ»¸ö°üÀ¨¡°Name¡±¡¢¡°Email¡±ºÍ¡°Phone¡±µÄ±íÍ·Êý×é £¬²¢½«Æäת´ï¸øÁËwithHeadings()ÒªÁì¡£

ʹÓÃfromArray()ÒªÁì

fromArray()ÒªÁìÊÇÁíÒ»¸öÉèÖñíÍ·µÄÒªÁì¡£ÓëwithHeadings()ÒªÁì²î±ð £¬ÎÒÃDz»ÐèҪʹÓÃfromArray()ÒªÁìÀ´»®·ÖÖ¸¶¨±íÍ·ºÍÊý¾Ý¡£

ʾÀý´úÂ룺

use MaatwebsiteExcelFacadesExcel;

Excel::create('my_excel_file', function($excel) {
    $excel->sheet('Sheet 1', function($sheet) {
        $data = [
            ['Name', 'Email', 'Phone'],
            ['John Doe', 'johndoe@gmail.com', '123-456-7890'],
            ['Jane Doe', 'janedoe@gmail.com', '123-456-7890'],
            ['Bob Smith', 'bobsmith@gmail.com', '123-456-7890']
        ];

        $sheet->fromArray($data);
    });
})->download('xlsx');

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öʾÀýÖÐ £¬ÎÒÃǽ«Õû¸ö±í¸ñ½ç˵Ϊһ¸öÊý×é £¬°üÀ¨±íÍ·ºÍÊý¾Ý £¬²¢½«Æäת´ï¸øÁËfromArray()ÒªÁì¡£

´ÓÊý¾Ý¿âÖÐÌáÈ¡Êý¾Ý²¢ÉèÖñíÍ·

ÎÒÃÇ¿ÉÒÔʹÓÃLaravel ModelÀ´´ÓÊý¾Ý¿âÖÐÌáÈ¡Êý¾Ý¡£ÎÒÃÇ¿ÉÒÔʹÓÃwithHeadings()ÒªÁìÀ´ÉèÖñíÍ·¡£

ʾÀý´úÂ룺

use AppUser;
use MaatwebsiteExcelFacadesExcel;

Excel::create('my_excel_file', function($excel) {
    $excel->sheet('Sheet 1', function($sheet) {
        $users = User::select('id', 'name', 'email')->get()->toArray();
        $sheet->with($users)->withHeadings(['ID', 'Name', 'Email']);
    });
})->download('xlsx');

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öʾÀýÖÐ £¬ÎÒÃÇʹÓÃEloquentÀ´»ñÈ¡Óû§Êý¾Ý²¢½«Æäת»»ÎªÊý×é¡£½ÓÏÂÀ´ £¬ÎÒÃÇʹÓÃwithHeadings()ÒªÁìÀ´ÉèÖñíÍ·¡£

½áÂÛ

ÔÚ±¾ÎÄÖÐ £¬ÎÒÃÇÏÈÈÝÁËÈýÖÖÉèÖÃLaravel Excel±íÍ·µÄÒªÁì¡£ÎÞÂÛÄãÊÇʹÓÃwithHeadings()ÒªÁì¡¢fromArray()ÒªÁìÕվɴÓÊý¾Ý¿âÖÐÌáÈ¡Êý¾Ý²¢ÉèÖñíÍ· £¬Laravel ExcelÈÃÌìÉúExcelÎļþ±äµÃºÜÊǼòÆÓ¡£Ï£Íû±¾ÎÄ¿ÉÒÔ×ÊÖúÄú¸üºÃµØʹÓÃLaravel Excel¡£

ÒÔÉϾÍÊÇlaravel excelÉèÖÃÍ·µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ