php wrote a batch of Excel import shipments, recorded under

Source: Internet
Author: User
This article introduces the content is about PHP wrote a batch of Excel import shipment, record, has a certain reference value, now share to everyone, have the need for friends can refer to

function Upexecel () {include ' data/extend/phpexcel_classes/phpexcel.php '; Determines if the table to be uploaded is selected if (Empty ($_post[' myfile ')) {echo "<script>alert (you have not selected a table); History.go ( -1); &LT;/SCR        Ipt> ";        }//Get the size of the table, limit the size of the upload table to 5M $file _size = $_files[' myfile ' [' Size ']; if ($file _size>5*1024*1024) {echo "<script>alert (' upload failed, the uploaded form cannot exceed 5M size '); History.go ( -1); </script&gt            ;";        Exit ();            }//Limit upload table type $file _name = $_files[' myfile ' [' name '];        Application/vnd.ms-excel for xls file type $extension = Strtolower (PathInfo ($file _name, pathinfo_extension)); Determine if the form was successfully uploaded if (is_uploaded_file ($_files[' myfile ' [' tmp_name '])) {//Receive Excel table in cache $filena            me = $_files[' myfile ' [' tmp_name ']; if ($extension = = ' xlsx ') {$objReader = \phpexcel_iofactory::createreader (' Excel2007 ');//use excel2007 for Format $objPHPExcel = $objREader->load ($filename); } else if ($extension = = ' xls ') {$objReader = \phpexcel_iofactory::createreader (' Excel5 ');//use excel2007 F            or in format $objPHPExcel = $objReader->load ($filename); }//$objPHPExcel = $objReader->load ($filename);            $filename can be an uploaded form, or a specified table $sheet = $objPHPExcel->getsheet (0); $highestRow = $sheet->gethighestrow (); Total number of rows obtained//$highestColumn = $sheet->gethighestcolumn ();  Get total columns//Loop through the Excel table, read one, insert a//j to start reading from the second line, because the first row is the title does not save/*if ($shipping _type = = 1) {$res = $order _service->orderdelivery ($order _id, $order _goods_id_array, $express _name, $shipping            _type, $express _company_id, $express _no, $suppliercode); */$order _service = new OrderService ();            $express = new Nsorderexpresscompanymodel ();            $num = 0; for ($j =2; $j <= $highestRow; $j + +) {               $a = $objPHPExcel->getactivesheet ()->getcell ("a". $j)->getvalue ();//order_id $b = $o Bjphpexcel->getactivesheet ()->getcell ("B". $j)->getvalue ();//order_goods_id $c = $objPHPExcel->g Etactivesheet ()->getcell ("C". $j)->getvalue ()//express_name $d = $objPHPExcel->getactivesheet ()-&G T;getcell ("D". $j)->getvalue ();//express_no $express _id = $express->where (' company_name ', $c)->value                (' co_id '); if (! $express _id | |!is_numeric ($d)) {echo "<script>alert". $j. "                    Line Express Company name or number is incorrect '); window.location.href= '/admin/spell/countspellgroup ';</script> ";                Break                } $res = $order _service->orderdelivery ($a, $b, $c, 1, $express _id, $d, ');                Exit (); Db::execute ("INSERT into Ns_wxmsg_spellgroup (orderid,msgtype,addtime,senttime,status) (select order_id, ' Ten ',". Time (). ", 0, ' from Ns_spelLgroup where pay_time>0 and order_id= ". $a.");            $num + +; } if ($num) {echo ' <script>alert ($num. ' Row data added successfully!            "Window.location.href= '/admin/spell/countspellgroup ';</script>"; }        }    }


Just started to write PHP, there are a lot of shortcomings, please correct me, I would like to write a business, temporarily did not fix, so first use, follow-up in the optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.