700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > php读取excel 以及php打包文件夹为zip文件

php读取excel 以及php打包文件夹为zip文件

时间:2022-08-17 01:22:13

相关推荐

php读取excel 以及php打包文件夹为zip文件

php教程|php手册

php,读取,excel,以及,打包,文件夹,为,zip,文件,php,读取,excel,以及,打包,文件夹,为,zip

php教程-php手册

php读取excel,以及php打包文件夹为zip文件,

简单的php留言系统源码,omp.h ubuntu,tomcat启动时运行类,爬虫订单多吗,php外包项目如何快速完成外包,seo蜗牛软件lzw

1.把文件下载到本地,放在在Apache环境下

2.d.xlsx是某游戏的服务器名和玩家列表,本程序只适合此种xlsx文件结构,其他结构请修改index.php源码

3.访问zip.php的功能是把生成的files文件夹打包成files.zip

4.访问index.php即可生成files文件夹,里面0.js---n.js 分别存放各个服务器人名,server_name_list.js存放服务器列表。

5.Classes 存放的是php读取excel的功能模块,具体任务逻辑都在index.php

A.PHP读取excel支持excel

demo逻辑代码:其中的(arrayRecursive,JSON方法是json数据处理功能,可兼容汉字)

主要借助了:PHPExcel插件,附件中有Classes文件夹,官网:/PHPExcel

index.php

标题1000) { die(possible deep recursion attack); } foreach ($array as $key => $value) { if (is_array($value)) {arrayRecursive($array[$key], $function, $apply_to_keys_also); } else {$array[$key] = $function($value); } if ($apply_to_keys_also && is_string($key)) {$new_key = $function($key);if ($new_key != $key) { $array[$new_key] = $array[$key]; unset($array[$key]);} } } $recursive_counter--; } /**************************************************************** 将数组转换为JSON字符串(兼容中文)* @param array $array要转换的数组* @return string转换得到的json字符串* @access public**************************************************************/ function JSON($array) { arrayRecursive($array, urlencode, true); $json = json_encode($array); return urldecode($json); } require_once Classes\PHPExcel.php;require_once Classes\PHPExcel\IOFactory.php;require_once Classes\PHPExcel\Reader\Excel.php;$uploadfile=d.xlsx; $objReader = PHPExcel_IOFactory::createReader(Excel);/*Excel5 for excel for */$objPHPExcel = PHPExcel_IOFactory::load($uploadfile); $sheet = $objPHPExcel->getSheet(0);$highestRow = $sheet->getHighestRow(); // 取得总行数$highestColumn = $sheet->getHighestColumn(); // 取得总列数/*方法【推荐】*/$objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); // 取得总行数 $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数$list = array(); for ($row = 1;$row <= $highestRow;$row++) {$strs=array();//注意highestColumnIndex的列数索引从0开始for ($col = 0;$col getCellByColumnAndRow($col, $row)->getValue();}array_push($list, $strs);} //读取完毕 $list //处理数据,生成新的结构 $n = 0; $ser = array(); for($i = 0 ; $i < count($list); $i++ ){ $ser[$n][0] = $list[$i][0]; if(!is_array(@$ser[$n][1])){ $ser[$n][1] = array(); } array_push($ser[$n][1], $list[$i][1]); if($i != count($list) -1){if($list[$i][0] != $list[$i+1][0]){$n++; } }} /*输出文件*/ $sname = array(); $f = files/;//存放目录 if (! file_exists ( $f )) { mkdir ( $f ); } for($j = 0;$j < count($ser); $j++){ $file = $f.$j..js; echo $file."

"; $fp=fopen("$file", "w+"); //打开文件指针,创建文件 if ( !is_writable($file) ){ die("文件:" .$file. "不可写,请检查!"); } if (is_writable($file) == false) {die(我是鸡毛,我不能); } $data = $ser[$j][1]; array_push($sname, $ser[$j][0]); file_put_contents ($file, JSON($data)); fclose($fp); //关闭指针 } $file = $f.server_name_list.js; echo $file."

";; $fp=fopen("$file", "w+"); //打开文件指针,创建文件 if ( !is_writable($file) ){ die("文件:" .$file. "不可写,请检查!"); } if (is_writable($file) == false) {die(我是鸡毛,我不能); } file_put_contents ($file, JSON($sname)); echo "生成完毕!"; echo 打包生成文件 ?>

B.PHP打包文件夹为zip文件

好看的导航源码,ubuntu调出dos界面,淘票票爬虫,php dopost(),js模版seolzw

zip.php

防手游平台源码,ubuntu盘重命名,scrap爬虫的运行,php . ..,360 审seolzw

标题addFile($path."/".$filename); } } } @closedir($path);}$zip=new ZipArchive();if($zip->open(files.zip, ZipArchive::OVERWRITE)=== TRUE){ addFileToZip(files, $zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法 $zip->close(); //关闭处理的zip文件}echo 打包完毕!."

";echo "下载files.zip"?>

代码下载:php-read-excel

/zhidong123/php-read-excel.zip

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。