PHP import Excel into MySQL database

Source: Internet
Author: User

<?phperror_reporting (e_all ^ e_notice); $img = Base64_decode ($base); $a = file_put_contents ('./test.jpg ', $img);// The number of bytes returned is print_r ($a); Require_once ' sdk/phpexcel.php ';///** the date in Excel is formatted to convert *///function GetData ($val) {//$jd = GREGORIANTOJD (1, 1, 1970);//$gregorian = Jdtogregorian ($jd +intval ($val) -25569);//return $gregorian;/** display format "month/day/year" "*///} $filePath = './excel/5a4b301c7124e.xls ';//var_dump (file_exists ($filePath)); $PHPExcel = new Phpexcel ();/** The default is to read Excel with excel2007, if the format is not correct, use the previous version to read */$PHPReader = new phpexcel_reader_excel2007 (); if (! $PHPReader->canread ($    FilePath) {$PHPReader = new Phpexcel_reader_excel5 ();        if (! $PHPReader->canread ($filePath)) {echo ' no Excel ';    return; }} $PHPExcel = $PHPReader->load ($filePath);/** reads the first worksheet in an Excel file */$currentSheet = $PHPExcel->getsheet (0);/** Get the largest column number */$allColumn = $currentSheet->gethighestcolumn ();/** get total number of lines */$allRow = $currentSheet->gethighestrow ( );/** starts the output from the second line because the first behavior in the Excel table is column name */for ($currentRow = 2; $currEntrow <= $allRow, $currentRow + +) {/** start output from column A/for ($currentColumn = ' a '; $currentColumn <= $allColumn; $currentC olumn++) {$val = $currentSheet->getcellbycolumnandrow (ord ($currentColumn)-+, $currentRow)->getvalue ();/**or D () Convert the character to decimal number */if ($currentColumn = = ' A ') {//Echo GetData ($val). "        \ t ";            }else{//echo $val; /** if the output character is garbled, the output will need to be encoded with the ICONV function to convert the GB2312 encoding into UTF-8 encoded output *///echo iconv (' Utf-8 ', ' gb2312 ', $val). "            \ t ";        $infos [$currentColumn]=iconv (' utf-8 ', ' gb2312 ', $val);    }}//echo "</br>";    $item =array ();    $item [' title ']= $infos [' C '];    $item [' Barcode ']= $infos [' D '];    $item [' default_image_id ']= $infos [' F '];    $item [' Store ']= $infos [' H '];    $item [' Price ']= $infos [' I '];    $item [' Offline_price ']= $infos [' J '];    $item [' shop_id ']= $infos [' K '];    $item [' desc ']= $infos [' L '];    Var_dump ($item); Exit ();} Var_dump ($info); echo "\ n";? >

  

PHP import Excel into MySQL database

Related Article

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.