将数组输出为excel文件
程序员文章站
2022-05-13 11:54:16
...
将数组输出为excel文件
<?php /** Error reporting */ error_reporting(E_ALL); /** PHPExcel */ include FCPATH.'vendor/Excel/excel/PHPExcel.php'; include FCPATH.'vendor/Excel/excel/PHPExcel/Writer/Excel5.php'; function download( $column , $datalist) { // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setCreator("Michael"); $objPHPExcel->getProperties()->setLastModifiedBy("MOT"); $objPHPExcel->getProperties()->setTitle("36lean email list"); $objPHPExcel->getProperties()->setSubject("Emails"); $objPHPExcel->getProperties()->setDescription("Array to Excel"); // Add some data $objPHPExcel->setActiveSheetIndex(0); $basic = 'A'; foreach ($column as $c) { $objPHPExcel->getActiveSheet()->SetCellValue( $basic.'1', $c); $basic ++ ; } $max_length = count( $datalist) - 1; for ($count = 0; $count <= $max_length; $count++) { $basic = 65; var_dump( $datalist[$count]); foreach ($datalist[$count] as $key => $d) { $basic = chr( $basic); $objPHPExcel->getActiveSheet()->SetCellValue( $basic.($count+2) , $d); $basic = ord( $basic) + 1; } $basic = 65; } //$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello'); // Rename sheet $objPHPExcel->getActiveSheet()->setTitle('Simple'); // Save Excel 2007 file $fhandle = opendir('data/download/'); while($file = readdir( $fhandle)) { if( is_file( 'data/download/'.$file)) { unlink( 'data/download/'.$file); } } $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); $filename = 'data/download/'.md5(time()).'.xls'; $objWriter->save($filename); return base_url( $filename); //header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //header('Cache-Control: max-age=0'); }
以上就是将数组输出为excel文件的内容,更多相关内容请关注PHP中文网(www.php.cn)!
推荐阅读
-
使用pandas将numpy中的数组数据保存到csv文件的方法
-
利用pandas将numpy数组导出生成excel的实例
-
Excel文件保存后多达10多M或以上打开或保存很慢如何将文件变小
-
Excel表格怎么批量导出图片将文件中的图片导出到文件夹中
-
Excel2010将表格的填充背景设置为中心辐射以凸显及美化表格
-
Excel可以截图吗如何将鼠标选中的单元格区域复制粘贴为图片
-
压缩文件rar怎么解压(将文件压缩为rar格式的方法)
-
python目录操作之python遍历文件夹后将结果存储为xml
-
python将字典列表导出为Excel文件的方法
-
Excel2010如何将工作表单元格中计算结果为0的零值隐藏