尊龙凯时人生就是搏

Laravel¿ª·¢£ºÔõÑùʹÓÃLaravel Excel´¦ÀíExcelÎļþ£¿

laravel¿ª·¢£ºÔõÑùʹÓÃlaravel excel´¦ÀíexcelÎļþ£¿

Laravel ExcelÊÇÒ»¸ö¿ªÔ´µÄLaravelÀ©Õ¹°ü £¬Ëü¿ÉÒÔ×ÊÖúÎÒÃǸüÀû±ãµØ´¦ÀíExcelÎļþ¡£ÔÚLaravelÏîÄ¿ÖÐʹÓÃLaravel Excel¿ÉÒÔʹÎÒÃǸü¿ì½Ý¡¢ÎÞаµØ¶ÁÈ¡¡¢Ð´ÈëºÍÐÞ¸ÄExcelÎļþ¡£

±¾ÎĽ«ÏÈÈÝLaravel ExcelµÄ×°ÖúÍʹÓÃÒªÁì £¬ÒÔ¼°ÔÚLaravelÏîÄ¿ÖÐÔõÑùʹÓÃLaravel ExcelÀ´´¦ÀíExcelÎļþ¡£

Ò»¡¢Laravel ExcelµÄ×°ÖÃ

ÔÚ¾ÙÐÐLaravel ExcelµÄ×°ÖÃ֮ǰ £¬È·±£ÒѾ­×°ÖúÃÁËLaravel¿ò¼Ü¡£

×°ÖÃLaravel Excel

ʹÓÃcomposerÀ´×°ÖÃLaravel Excel £¬ÏÂÁîÈçÏ£º

composer require maatwebsite/excel

µÇ¼ºó¸´ÖÆ

ÉèÖÃ

×°ÖÃÍê³ÉÖ®ºó £¬ÐèÒªÔÚconfig/app.phpÉèÖÃÎļþÖмÓÈëLaravel ExcelµÄServiceProviderºÍFacades¡£

Ç뽫ÒÔÏ´úÂ븴ÖƵ½config/app.phpµÄprovidersÊý×éÖУº

MaatwebsiteExcelExcelServiceProvider::class,

µÇ¼ºó¸´ÖÆ

ͬʱ £¬½«ÒÔÏ´úÂ븴ÖƵ½config/app.phpµÄaliasesÊý×éÖУº

'Excel' => MaatwebsiteExcelFacadesExcel::class,

µÇ¼ºó¸´ÖÆ

ÕâÑù¾ÍÍê³ÉÁËLaravel ExcelµÄ×°ÖúÍÉèÖá£

¶þ¡¢Laravel ExcelµÄʹÓÃ

ÏÂÃ潫ÏÈÈÝLaravel ExcelµÄʹÓÃÒªÁì¡£

¶ÁÈ¡ExcelÎļþ

ʹÓÃLaravel Excel¿ÉÒÔÇáËɵضÁÈ¡ExcelÎļþ £¬¾ÍÏñ¶ÁÈ¡Êý¾Ý¿âÒ»Ñù¡£¿ÉÒÔʹÓÃÒÔÏ´úÂë¶ÁÈ¡ExcelÎļþ£º

use MaatwebsiteExcelFacadesExcel;

Excel::load('Îļþ·¾¶', function($reader) {
    // »ñÈ¡ExcelÎļþÖеÄËùÓÐÊý¾Ý
    $results = $reader->get();

    // ±éÀúÿһÐÐÊý¾Ý
    foreach ($results as $row) {
        // ´¦ÀíÿһÐÐÊý¾Ý
    }
});

µÇ¼ºó¸´ÖÆ

ÔÚ¶ÁÈ¡ExcelÎļþÖ®ºó £¬¿ÉÒÔ¶ÔÿһÐÐÊý¾Ý¾ÙÐд¦Àí¡£ÈôÊÇExcelÎļþÖб£´æ¶à¸ö±í¸ñ £¬¿ÉÒÔʹÓÃsheet()ÒªÁìÖ¸¶¨Òª¶ÁÈ¡µÄ±í¸ñ £¬ÈçÏÂËùʾ£º

Excel::selectSheets('±í¸ñÃû³Æ')->load('Îļþ·¾¶', function($reader) {
    // »ñÈ¡±í¸ñÖеÄËùÓÐÊý¾Ý
    $results = $reader->get();

    // ±éÀúÿһÐÐÊý¾Ý
    foreach ($results as $row) {
        // ´¦ÀíÿһÐÐÊý¾Ý
    }
});

µÇ¼ºó¸´ÖÆ

дÈëExcelÎļþ

ʹÓÃLaravel Excel¿ÉÒÔÀû±ãµØ½«Êý¾ÝдÈëExcelÎļþÖÐ £¬Ö»ÐèÒª½«Êý¾ÝÃûÌû¯ÎªExcelÖ§³ÖµÄÃûÌü´¿É¡£¿ÉÒÔʹÓÃÒÔÏ´úÂ뽫Êý¾ÝдÈëExcelÎļþÖУº

use MaatwebsiteExcelFacadesExcel;

Excel::create('ÎļþÃû', function($excel) {

    // ½¨ÉèÒ»¸öÊÂÇé±í
    $excel->sheet('Sheet1', function($sheet) {

        // дÈëÊý¾Ý
        $sheet->row(1, array(
            'ÐÕÃû', 'ÄêËê', 'ÐÔ±ð'
        ));
        $sheet->row(2, array(
            'СÃ÷', 20, 'ÄÐ'
        ));
        $sheet->row(3, array(
            'Сºì', 18, 'Å®'
        ));

    });

})->store('xls', 'Îļþ·¾¶');

µÇ¼ºó¸´ÖÆ

ÔÚÖ´ÐÐstore()ÒªÁìÖ®ºó £¬ExcelÎļþ¾Í»á±»ÉúÑÄÔÚÖ¸¶¨µÄ·¾¶ÖС£

ÐÞ¸ÄExcelÎļþ

ʹÓÃLaravel ExcelÒ²¿ÉÒÔºÜÀû±ãµØÐÞ¸ÄExcelÎļþÖеÄÊý¾Ý¡£¿ÉÒÔʹÓÃÒÔÏ´úÂëÐÞ¸ÄExcelÎļþÖеÄÊý¾Ý£º

use MaatwebsiteExcelFacadesExcel;

Excel::load('Îļþ·¾¶', function($reader) {

    // »ñÈ¡ExcelÎļþÖеÄËùÓÐÊý¾Ý
    $results = $reader->get();

    // ±éÀúÿһÐÐÊý¾Ý
    foreach ($results as $row) {

        // ÅжÏÊÇ·ñÐèÒªÐ޸ĸÃÐÐÊý¾Ý
        if (...) {
            // ÐÞ¸ÄÊý¾Ý
            $row->column1 = 'еÄÖµ';
            $row->column2 = 'еÄÖµ';
            // ...
        }

    }

    // ½«Ð޸ĺóµÄÊý¾ÝÉúÑĵ½Ô­ExcelÎļþÖÐ
    $reader->export('xls');

});

µÇ¼ºó¸´ÖÆ

ÔÚÐÞ¸ÄÊý¾ÝÖ®ºó £¬Ê¹ÓÃexport()ÒªÁ콫Ð޸ĺóµÄÊý¾ÝÉúÑĵ½Ô­ExcelÎļþÖС£

½áÓï

±¾ÎÄÏÈÈÝÁËÔõÑù×°ÖúÍʹÓÃLaravel ExcelÀ´´¦ÀíExcelÎļþ¡£Í¨¹ýʹÓÃLaravel Excel £¬ÎÒÃÇ¿ÉÒÔ¸üÀû±ãµØ¶ÁÈ¡¡¢Ð´ÈëºÍÐÞ¸ÄExcelÎļþ £¬Ìá¸ß¿ª·¢Ð§ÂÊ £¬ïÔÌ­·±ËöµÄExcelÎļþ´¦ÀíÊÂÇé¡£

ÒÔÉϾÍÊÇLaravel¿ª·¢£ºÔõÑùʹÓÃLaravel Excel´¦ÀíExcelÎļþ£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

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

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

QR code
sitemap¡¢ÍøÕ¾µØͼ