How does phpexcel import excel to process big data code examples?

黄舟
Release: 2023-03-15 14:14:01
Original
4169 people have browsed it

The following editor will bring you an article about importing phpexcel into excel to process big data (explanation with examples). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let's follow the editor and take a look.

Just download the package corresponding to phpExcel first.

After the download is completed, just take out the files and folders in the Classes folder.

Write directly to the PHPExcel file. The call is simple. Introduce the phpExcel class to pass the path of the corresponding excel file.

Now upload to the specified directory, and then load the uploaded excel file to read. The array will not be converted when reading here. Note: Sheets can be read multiple times, the PHP upload value must be set large, and the upload timeout must be set long.

header('Content-type: text/html; charset=utf-8'); //设置页面编码
require_once 'phpexcel.class.php'; //引入文件
require_once 'PHPExcel/IOFactory.php'; //引入文件
require_once 'PHPExcel/Reader/Excel2007.php'; //引入文件
$uploadfile = $_FILES['select_file']['tmp_name'];  //获取上传文件
$auid = $_SESSION['auid'];
$date = date('Ymd');
$rand = rand(1,9999);
$_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; //上传文件目录指定
move_uploaded_file($uploadfile, $path_file); //文件上传

$inputFileType = PHPExcel_IOFactory::identify($path_file);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);//只需要添加这个方法实现表格数据格式转换
$objPHPExcel = $objReader->load($path_file);

$sheet_read_arr = array();
$sheet_read_arr["表1"] = array("B","C");
$sheet_read_arr["表2"] = array("B","C");
$sheet_read_arr["表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_values[] = $currentSheet->getCell($address)->getFormattedValue();
  }
  $list_aray[]=$cell_values;
 }
}
Copy after login

The above is the detailed content of How does phpexcel import excel to process big data code examples?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!