php 导出excel压缩包
来源:互联网 发布:大数据存储技术研究 编辑:程序博客网 时间:2024/06/05 16:15
//创建文件夹或清除文件夹下文件$dir="var/templet";if (!file_exists($dir)){ mkdir ($dir);//创建文件夹}else{ $dh=opendir($dir); while ($file=readdir($dh)) { if($file!="." && $file!="..") { $fullpath=$dir."/".$file; unlink($fullpath); } } closedir($dh);}//导出excel//导出单个品类码excel $oe = new PHPExcel(); $i = 0; $x = 1; $oe->setActiveSheetIndex(0); $oe->getActiveSheet()->setTitle('品类码'.$category_code); $oe->getActiveSheet()->setCellValue('A1', '品类码:'.$category_code); $oe->getActiveSheet()->setCellValue('A2',$manage_full_name);// $oe->getActiveSheet()->setCellValue('B1', $manage_code); $oe->getActiveSheet()->getColumnDimension('A')->setWidth(50);// $oe->getActiveSheet()->getColumnDimension('B')->setWidth(50); foreach ($excel_data as $kk=>$data){ $oe->addSheet(new PHPExcel_Worksheet($oe, $kk)); $i += 1; } foreach ($excel_data as $kk=>$data){ $oe->setActiveSheetIndex($x); $column = "A"; $column++; $column++; foreach ($data as $j=>$template_field) { $column++; $oe->getActiveSheet()->setCellValue('A1', 'ERPSKU'); $oe->getActiveSheet()->setCellValue('B1', 'Account'); $oe->getActiveSheet()->setCellValue('C1', 'SellerSku'); $oe->getActiveSheet()->getColumnDimension($column)->setWidth(20); if($template_field['field_type'] == 4){ $oe->getActiveSheet()->getStyle($column)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00); } $oe->getActiveSheet()->setCellValue($column . '1', $template_field['template_name']); $oe->getActiveSheet()->getColumnDimension($column)->setWidth(20); $oe->getActiveSheet()->getComment( $column . '1')->setAuthor('PHPExcel' ); //设置作者 $oe->getActiveSheet()->getComment($column .'1' )->getText()-> createTextRun($template_field['template_description']); $oe->getActiveSheet()->getComment( $column . '1' )->setWidth('150pt' )->setHeight('150pt'); }$currentRow = 1; foreach($rowData as $rowSet=>$row){ $column2="A"; $currentColumn = 0 ; foreach ($row as $order=>$item){// $oe->getActiveSheet()->setCellValue(chr($colbaseIndex+$currentColumn) . ($currentRow+1), $item); $oe->getActiveSheet()->setCellValue($column2 . ($currentRow+1), $item); $column2++; $currentColumn++; } $currentRow++; } $x += 1; }// var_dump($erpskus[$category_code]);// exit(); $objWriter = PHPExcel_IOFactory::createWriter($oe, "Excel2007"); $file ='var/templet/'.$line_name.'_'.$category_code.'.xlsx'; $objWriter->save($file); $oe->disconnectWorksheets(); unset($oe);//打包//zip打包$dir='var/templet';$datalist = array();if (is_dir($dir)){ $file_dir = scandir($dir); foreach($file_dir as $file){ if ($file == '.' || $file == '..'){ continue; }else{ array_push($datalist, $dir."/".$file); } }}//$datalist 就是指 导出的excel的数量,数量为1的时,则以Excel格式导出if (count($datalist) == 1 ){ header("Location: /$datalist[0]"); exit;}//$filename = "var/templet/templet.zip"; //最终生成的文件名(含路径)$filename = "var/templet/".$line_name."_templet.zip"; //最终生成的文件名(含路径)//生成文件$zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { exit('无法打开文件,或者文件创建失败');}foreach( $datalist as $val){ if(file_exists($val)){ $zip->addFile( $val, basename($val));//第二个参数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下 }}$zip->close();//关闭if(!file_exists($filename)){ exit("无法找到文件"); //即使创建,仍有可能失败。。。。}header("Location: /$filename");exit;// end zip打包
阅读全文
0 0
- php 导出excel压缩包
- 数据导出-excel,excel压缩包
- 压缩包里面excel 导出 (跨行跨列)
- 将EXCEL导出成ZIP压缩包
- excel导出之大量数据-导出压缩包
- 大于65535的数据GridView导出Excel压缩包
- 导出Zip压缩Excel
- java 导出压缩包
- 导出压缩包
- php 压缩zip包压缩
- java导出excel并压缩
- Java 让excel导出大量数据进行分表打成压缩包进行下载
- Java通过Spring MVC导出批量Excel文件压缩包,并弹出下载框
- php导出excel
- PHP 导出EXCEL报表
- php导出Excel方法
- PHP导出Excel文件
- php导出Excel
- CodeForces 424 Div2 CBA题
- Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]
- Java 反射 使用总结
- List Copy
- HDU--2151--Worm(动态规划)
- php 导出excel压缩包
- 树状数组,离散化,突破口(Segment Game,HDU 5372)
- java socket文件传输
- gRPC的使用(二)之异步服务器流RPC的使用流程
- RocketMQ配置
- ORA-12154TNS
- 练习1-return-try-canth-fianlly和方法形参的传递
- Cassandra错误总结
- for in、for of、forEach的区别