Import phpexcel to excel to process big data, and import phpexcel to excel

Source: Internet
Author: User

Import phpexcel to excel to process big data, and import phpexcel to excel

First download the corresponding phpExcel package on the line of the https://github.com/PHPOffice/PHPExcel
After the download is complete, just take out the files and folders in the Classes folder.
Directly written to the PHPExcel file. The call is simple. Introduce phpExcel to transfer the corresponding excel file path.
Now upload the file to the specified directory and then load the uploaded excel file to read the file. when reading the file here, the array is not converted. Note: Sheet can be read multiple times. The php Upload value must be set to a large value and the upload timeout value must be set to a long value.

Header ('content-type: text/html; charset = UTF-8 '); // sets the page encoding require_once' phpexcel. class. php '; // introduce the file require_once' PHPExcel/IOFactory. php '; // introduce the file require_once 'phpexcel/Reader/excel2007.php '; // introduce the file $ uploadfile =$ _ FILES ['select _ file'] ['tmp _ name']; // obtain the uploaded file $ auid =$ _ SESSION ['auid']; $ date = date ('ymmd'); $ rand = rand ); $ _ month = str_replace ('-', '', $ date); $ file_name = str_pad ($ auid, 4, 0, STR_PAD_LEFT ). $ date. str_pad ($ rand, 4, 0, STR_PAD_LEFT).'.xlsx '; $ path_file = '.. /data/upload/file /'. $ file_name; // specify move_uploaded_file ($ uploadfile, $ path_file) in the Upload File directory; // File Upload $ inputFileType = PHPExcel_IOFactory: identify ($ path_file); $ objReader = PHPExcel_IOFactory :: createReader ($ inputFileType); $ objReader-> setReadDataOnly (true); // you only need to add this method to convert the table data format $ objPHPExcel = $ objReader-> load ($ path_file ); $ sheet_read_arr = array (); $ sheet_read_arr ["table 1"] = array ("B", "C "); $ sheet_read_arr ["Table 2"] = array ("B", "C"); $ sheet_read_arr ["Table 3"] = array ("B", "C "); $ list_aray = array (); foreach ($ sheet_read_arr as $ key => $ val) {$ currentSheet = $ objPHPExcel-> getSheetByName ($ key ); $ row_num = $ currentSheet-> getHighestRow (); for ($ I = 6; $ I <= $ row_num; $ I ++) {$ cell_values = array (); foreach ($ val as $ cell_val) {$ address = $ cell_val. $ I; // cell coordinates $ cell_values [] = $ currentSheet-> getCell ($ address)-> getFormattedValue ();} $ list_aray [] = $ cell_values ;}}

 

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.