123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677 |
- <?php
- /**
- * lionfish 商城系统
- *
- * ==========================================================================
- * @link http://www.liofis.com/
- * @copyright Copyright (c) 2015 liofis.com.
- * @license http://www.liofis.com/license.html License
- * ==========================================================================
- *
- * @author fish
- *
- */
- namespace Seller\Model;
- class ExcelModel{
-
-
- protected function column_str($key)
- {
- $array = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ', 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ', 'CA', 'CB', 'CC', 'CD', 'CE', 'CF', 'CG', 'CH', 'CI', 'CJ', 'CK', 'CL', 'CM', 'CN', 'CO', 'CP', 'CQ', 'CR', 'CS', 'CT', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DA', 'DB', 'DC', 'DD', 'DE', 'DF', 'DG', 'DH', 'DI', 'DJ', 'DK', 'DL', 'DM', 'DN', 'DO', 'DP', 'DQ', 'DR', 'DS', 'DT', 'DU', 'DV', 'DW', 'DX', 'DY', 'DZ', 'EA', 'EB', 'EC', 'ED', 'EE', 'EF', 'EG', 'EH', 'EI', 'EJ', 'EK', 'EL', 'EM', 'EN', 'EO', 'EP', 'EQ', 'ER', 'ES', 'ET', 'EU', 'EV', 'EW', 'EX', 'EY', 'EZ');
- return $array[$key];
- }
- protected function column($key, $columnnum = 1)
- {
- return $this->column_str($key) . $columnnum;
- }
-
- public function export_delivery_goodslist( $list, $params = array() )
- {
- if (PHP_SAPI == 'cli') {
- exit('This example should only be run from a Web Browser');
- }
-
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel.php';
- $excel = new \PHPExcel();
-
- $excel->getProperties()->setCreator('狮子鱼商城')->setLastModifiedBy('狮子鱼商城')->setTitle('Office 2007 XLSX Test Document')->setSubject('Office 2007 XLSX Test Document')->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('report file');
- $sheet = $excel->setActiveSheetIndex(0);
- $rownum = 1;
-
- $list_info = $params['list_info'];
-
-
- $sheet->setCellValue('A1', $list_info['line1']);
-
- //$sheet->mergeCells('A1:C1');
- $rownum++;
-
- $sheet->setCellValue('A2', $list_info['line2']);
- //$sheet->mergeCells('A2:C2');
- $rownum++;
-
-
- foreach ($params['columns'] as $key => $column ) {
- $sheet->setCellValue($this->column($key, $rownum), $column['title']);
- if (!(empty($column['width']))) {
- $sheet->getColumnDimension($this->column_str($key))->setWidth($column['width']);
- }
- }
- ++$rownum;
- $len = count($params['columns']);
- foreach ($list as $row ) {
- $i = 0;
- while ($i < $len) {
- $value = ((isset($row[$params['columns'][$i]['field']]) ? $row[$params['columns'][$i]['field']] : ''));
- $sheet->setCellValue($this->column($i, $rownum), $value);
- ++$i;
- }
- ++$rownum;
- }
-
-
-
- $excel->getActiveSheet()->setTitle($params['title']);
- $filename = ($params['title'] . '-' . date('Y-m-d H:i', time()));
-
-
- $excel->getActiveSheet()->setTitle($params['title']);
- $filename = ($params['title'] . '-' . date('Y-m-d H:i', time()));
-
- header('pragma:public');
- header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$params['title'].'.xls"');
- header("Content-Disposition:attachment;filename=".$filename.".xls");//attachment新窗口打印inline本窗口打印
- $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
- $objWriter->save('php://output');
- exit;
-
- }
-
-
- public function export_delivery_list_pinew($params_list, $list = array())
- {
- if (PHP_SAPI == 'cli') {
- exit('This example should only be run from a Web Browser');
- }
-
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel.php';
- $excel = new \PHPExcel();
-
- $excel->getProperties()->setCreator('狮子鱼商城')->setLastModifiedBy('狮子鱼商城')->setTitle('Office 2007 XLSX Test Document')->setSubject('Office 2007 XLSX Test Document')->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('report file');
- $sheet = $excel->setActiveSheetIndex(0);
-
-
- /**
- ["200_"]=>
- array(4) {
- ["goods_name"]=>
- string(15) "牙刷【李】"
- ["goods_goodssn"]=>
- string(0) ""
- ["goods_count"]=>
- int(10)
- ["head_goods_list"]=>
- array(2) {
- [1]=>
- array(5) {
- ["price"]=>
- string(6) "0.0100"
- ["total_price"]=>
- float(0.09)
- ["buy_quantity"]=>
- int(9)
- ["head_name"]=>
- string(11) "15865422541"
- ["total_quatity"]=>
- int(9)
- }
- [118]=>
- array(5) {
- ["price"]=>
- string(6) "0.0100"
- ["total_price"]=>
- float(0.01)
- ["buy_quantity"]=>
- string(1) "1"
- ["head_name"]=>
- string(11) "18919633344"
- ["total_quatity"]=>
- string(1) "1"
- }
- }
- }
- **/
- $sheet->setCellValue('A1', '序号');
- $sheet->setCellValue('B1', '商品编码');
- $sheet->setCellValue('C1', '商品名称');
- $sheet->setCellValue('D1', '规格');
- $sheet->setCellValue('E1', '单价');
- $sheet->setCellValue('F1', '总价');
- $sheet->setCellValue('G1', '订购数');
- $sheet->setCellValue('H1', '团长');
- $sheet->setCellValue('I1', '小区');
- $sheet->setCellValue('J1', '合计数');
-
-
-
- $i =1;
- $rownum = 1;
-
-
-
- foreach( $params_list as $params )
- {
- $next_postion_begin = $rownum + 1;
-
- for($j=1;$j<= count($params['head_goods_list']); $j++)
- {
- $rownum++;
- }
-
- if( count($params['head_goods_list']) > 1 )
- {
- //需要合并了
- $sheet->mergeCells('A'.$next_postion_begin.':A'.$rownum);
- $sheet->getStyle('A'.$next_postion_begin.':A'.$rownum)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
-
- $sheet->mergeCells('B'.$next_postion_begin.':B'.$rownum);
- $sheet->getStyle('B'.$next_postion_begin.':B'.$rownum)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
-
- $sheet->mergeCells('C'.$next_postion_begin.':C'.$rownum);
- $sheet->getStyle('C'.$next_postion_begin.':C'.$rownum)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
-
-
- $sheet->mergeCells('D'.$next_postion_begin.':D'.$rownum);
- $sheet->getStyle('D'.$next_postion_begin.':D'.$rownum)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
-
-
- $sheet->mergeCells('J'.$next_postion_begin.':J'.$rownum);
- $sheet->getStyle('J'.$next_postion_begin.':J'.$rownum)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
-
- }
-
- $sheet->setCellValue('A'.$next_postion_begin , $i);
- $sheet->setCellValue('B'.$next_postion_begin , $params['goods_goodssn'] );
- $sheet->setCellValue('C'.$next_postion_begin , $params['goods_name'] );
- $sheet->setCellValue('D'.$next_postion_begin , $params['sku_str'] );
-
- $k = $next_postion_begin;
- foreach( $params['head_goods_list'] as $head_goods )
- {
- $sheet->setCellValue('E'.$k , $head_goods['price'] );
- $sheet->setCellValue('F'.$k , $head_goods['total_price'] );
- $sheet->setCellValue('G'.$k , $head_goods['buy_quantity'] );
- $sheet->setCellValue('H'.$k , $head_goods['head_name'] );
- $sheet->setCellValue('I'.$k , $head_goods['community_name'] );
- $k++;
- }
-
- $sheet->setCellValue('J'.$next_postion_begin , $params['goods_count'] );
- $i++;
- }
-
-
-
- $excel->getActiveSheet()->setTitle($list['title']);
-
-
- $filename = ($list['title'] . '-' . date('Y-m-d H:i', time()));
-
- header('pragma:public');
- header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$params['title'].'.xls"');
- header("Content-Disposition:attachment;filename=".$filename.".xls");//attachment新窗口打印inline本窗口打印
- $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
- $objWriter->save('php://output');
- exit;
-
-
-
-
-
-
- $excel->getActiveSheet()->setTitle($list['title']);
-
-
- $filename = ($list['title'] . '-' . date('Y-m-d H:i', time()));
-
- header('pragma:public');
- header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$params['title'].'.xls"');
- header("Content-Disposition:attachment;filename=".$filename.".xls");//attachment新窗口打印inline本窗口打印
- $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
- $objWriter->save('php://output');
- exit;
-
- }
-
- /**
- 批量导出团长配送清单
- **/
- public function export_delivery_list_pi( $params_list, $list = array() )
- {
- if (PHP_SAPI == 'cli') {
- exit('This example should only be run from a Web Browser');
- }
-
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel.php';
- $excel = new \PHPExcel();
-
- $excel->getProperties()->setCreator('狮子鱼商城')->setLastModifiedBy('狮子鱼商城')->setTitle('Office 2007 XLSX Test Document')->setSubject('Office 2007 XLSX Test Document')->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('report file');
- $sheet = $excel->setActiveSheetIndex(0);
-
- $rownum = 1;
- foreach( $params_list as $params )
- {
-
- $list_info = $params['list_info'];
-
- $line1 = $list_info['head_name'];
- $line2 = '团长:'.$list_info['head_name'].' 提货地址:'.$list_info['head_address'].' 联系电话:'.$list_info['head_mobile'];
- //$line3 = $list_info['list_sn'].' 时间:'.date('Y-m-d H:i:s', $list_info['create_time']);
- //$line3 = '时间:'.date('Y-m-d H:i:s', $list_info['create_time']);
- $line3 = '检索条件:'.$list_info['search_tiaoj'];
- $line4 = '配送路线:'.$list_info['line_name'].' 配送员:'.$list_info['clerk_name'];
-
- $sheet->setCellValue('A'.$rownum, $line1);
-
-
- $rownum++;
-
- $sheet->setCellValue('A'.$rownum, $line2);
- $rownum++;
-
- $sheet->setCellValue('A'.$rownum, $line3);
-
- $rownum++;
-
- $sheet->setCellValue('A'.$rownum, $line4);
-
- $rownum++;
- $rownum++;
-
-
- foreach ($list['columns'] as $key => $column ) {
- $sheet->setCellValue($this->column($key, $rownum), $column['title']);
- if (!(empty($column['width']))) {
- $sheet->getColumnDimension($this->column_str($key))->setWidth($column['width']);
- }
- }
- ++$rownum;
- $len = count($list['columns']);
-
-
- foreach ($params['data'] as $row ) {
- $i = 0;
-
- while ($i < $len) {
-
- $value = ((isset($row[$list['columns'][$i]['field']]) ? $row[$list['columns'][$i]['field']] : ''));
-
-
- $sheet->setCellValue($this->column($i, $rownum), $value);
- ++$i;
- }
- ++$rownum;
- }
-
- $rownum++;
- $rownum++;
-
- }
-
-
-
- $excel->getActiveSheet()->setTitle($list['title']);
-
-
- $filename = ($list['title'] . '-' . date('Y-m-d H:i', time()));
-
- header('pragma:public');
- header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$params['title'].'.xls"');
- header("Content-Disposition:attachment;filename=".$filename.".xls");//attachment新窗口打印inline本窗口打印
- $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
- $objWriter->save('php://output');
- exit;
-
- }
-
-
- public function export_delivery_list($list, $params = array())
- {
- if (PHP_SAPI == 'cli') {
- exit('This example should only be run from a Web Browser');
- }
-
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel.php';
- $excel = new \PHPExcel();
-
- $excel->getProperties()->setCreator('狮子鱼商城')->setLastModifiedBy('狮子鱼商城')->setTitle('Office 2007 XLSX Test Document')->setSubject('Office 2007 XLSX Test Document')->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('report file');
- $sheet = $excel->setActiveSheetIndex(0);
- $rownum = 1;
-
- $list_info = $params['list_info'];
-
- $sheet->setCellValue('A1', $list_info['line1']);
-
-
- //$sheet->mergeCells('A1:D1');
- $rownum++;
-
- $sheet->setCellValue('A2', $list_info['line2']);
- //$sheet->mergeCells('A2:D2');
- $rownum++;
-
- $sheet->setCellValue('A3', $list_info['line3']);
- //$sheet->mergeCells('A3:D3');
- $rownum++;
-
- $sheet->setCellValue('A4', $list_info['line4']);
- //$sheet->mergeCells('A4:D4');
- $rownum++;
-
-
- foreach ($params['columns'] as $key => $column ) {
- $sheet->setCellValue($this->column($key, $rownum), $column['title']);
- if (!(empty($column['width']))) {
- $sheet->getColumnDimension($this->column_str($key))->setWidth($column['width']);
- }
- }
- ++$rownum;
- $len = count($params['columns']);
- foreach ($list as $row ) {
- $i = 0;
- while ($i < $len) {
- $value = ((isset($row[$params['columns'][$i]['field']]) ? $row[$params['columns'][$i]['field']] : ''));
- $sheet->setCellValue($this->column($i, $rownum), $value);
- ++$i;
- }
- ++$rownum;
- }
-
-
-
- $excel->getActiveSheet()->setTitle($params['title']);
- $filename = ($params['title'] . '-' . date('Y-m-d H:i', time()));
-
-
- header('pragma:public');
- header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$params['title'].'.xls"');
- header("Content-Disposition:attachment;filename=".$filename.".xls");//attachment新窗口打印inline本窗口打印
- $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
- $objWriter->save('php://output');
- exit;
-
- }
-
-
- /**
- * 导出Excel
- * @param type $list
- * @param type $params
- */
- public function export($list, $params = array())
- {
- if (PHP_SAPI == 'cli') {
- exit('This example should only be run from a Web Browser');
- }
-
- //ThinkPHP\Library\Vendor\ROOT_PATH
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel.php';
- $excel = new \PHPExcel();
-
- $excel->getProperties()->setCreator('狮子鱼商城')->setLastModifiedBy('狮子鱼商城')->setTitle('Office 2007 XLSX Test Document')->setSubject('Office 2007 XLSX Test Document')->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('report file');
- $sheet = $excel->setActiveSheetIndex(0);
- $rownum = 1;
- foreach ($params['columns'] as $key => $column ) {
- $sheet->setCellValue($this->column($key, $rownum), $column['title']);
- if (!(empty($column['width']))) {
- $sheet->getColumnDimension($this->column_str($key))->setWidth($column['width']);
- }
- }
- ++$rownum;
- $len = count($params['columns']);
- foreach ($list as $row ) {
- $i = 0;
- while ($i < $len) {
- $value = ((isset($row[$params['columns'][$i]['field']]) ? $row[$params['columns'][$i]['field']] : ''));
- $sheet->setCellValue($this->column($i, $rownum), $value);
- ++$i;
- }
- ++$rownum;
- }
- $excel->getActiveSheet()->setTitle($params['title']);
- $filename = ($params['title'] . '-' . date('Y-m-d H:i', time()));
-
-
-
- header('pragma:public');
- header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$params['title'].'.xls"');
- header("Content-Disposition:attachment;filename=".$filename.".xls");//attachment新窗口打印inline本窗口打印
- $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
- $objWriter->save('php://output');
- exit;
- }
- /**
- * @param $objWriter PHPExcel_Writer_IWriter
- */
- public function SaveViaTempFile($objWriter)
- {
- $filePath = '' . rand(0, getrandmax()) . rand(0, getrandmax()) . '.tmp';
- $objWriter->save($filePath);
- readfile($filePath);
- unlink($filePath);
- }
- /**
- * 生成模板文件Excel
- * @param type $list
- * @param type $params
- */
- public function temp($title, $columns = array())
- {
- if (PHP_SAPI == 'cli') {
- exit('This example should only be run from a Web Browser');
- }
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel.php';
- $excel = new \PHPExcel();
- $excel->getProperties()->setCreator('狮子鱼商城')->setLastModifiedBy('狮子鱼商城')->setTitle('Office 2007 XLSX Test Document')->setSubject('Office 2007 XLSX Test Document')->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('report file');
- $sheet = $excel->setActiveSheetIndex(0);
- $rownum = 1;
- foreach ($columns as $key => $column ) {
- $sheet->setCellValue($this->column($key, $rownum), $column['title']);
- if (!(empty($column['width']))) {
- $sheet->getColumnDimension($this->column_str($key))->setWidth($column['width']);
- }
- }
- ++$rownum;
- $len = count($columns);
- $k = 1;
- while ($k <= 5000) {
- $i = 0;
- while ($i < $len) {
- $sheet->setCellValue($this->column($i, $rownum), '');
- ++$i;
- }
- ++$rownum;
- ++$k;
- }
- $excel->getActiveSheet()->setTitle($title);
- $filename = ($title);
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment;filename="' . $filename . '.xls"');
- header('Cache-Control: max-age=0');
- $writer = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
- $writer->save('php://output');
- exit();
- }
- public function import($excefile)
- {
-
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel.php';
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel/IOFactory.php';
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel/Reader/Excel5.php';
- $path = ROOT_PATH . '/Uploads/image/'.date('Y-m-d').'/';
- if (!(is_dir($path))) {
- RecursiveMkdir($path);
- }
- $filename = $_FILES[$excefile]['name'];
- $tmpname = $_FILES[$excefile]['tmp_name'];
- if (empty($tmpname)) {
- message('请选择要上传的Excel文件!', '', 'error');
- }
- $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
- if (($ext != 'xlsx') && ($ext != 'xls')) {
- //message('请上传 xls 或 xlsx 格式的Excel文件!', '', 'error');
- }
- $file = time() . 1 . '.' . $ext;
- $uploadfile = $path . $file;
- $result = move_uploaded_file($tmpname, $uploadfile);
- if (!($result)) {
- //message('上传Excel 文件失败, 请重新上传!', '', 'error');
- }
- $reader = \PHPExcel_IOFactory::createReader(($ext == 'xls' ? 'Excel5' : 'Excel2007'));
- $excel = $reader->load($uploadfile);
- $sheet = $excel->getActiveSheet();
- $highestRow = $sheet->getHighestRow();
- $highestColumn = $sheet->getHighestColumn();
- $highestColumnCount = \PHPExcel_Cell::columnIndexFromString($highestColumn);
- $values = array();
- $row = 1;
- while ($row <= $highestRow) {
- $rowValue = array();
- $col = 0;
- while ($col < $highestColumnCount) {
- $rowValue[] = (string) $sheet->getCellByColumnAndRow($col, $row)->getValue();
- ++$col;
- }
- $values[] = $rowValue;
- ++$row;
- }
- return $values;
- }
- /**
- * 添加了商品列表到处excel
- * @author 刘鑫芮 2020-03-02
- * @param $params 到处excel参数
- * @param $list 商品数据
- * */
- public function export_goods_list_pi( $params, $list = array() ) {
- if (PHP_SAPI == 'cli') {
- exit('This example should only be run from a Web Browser');
- }
- require_once ROOT_PATH . '/ThinkPHP/Library/Vendor/phpexcel/PHPExcel.php';
- $excel = new \PHPExcel();
- $excel->getProperties()->setCreator('狮子鱼商城')->setLastModifiedBy('狮子鱼商城')->setTitle('Office 2007 XLSX Test Document')->setSubject('Office 2007 XLSX Test Document')->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('report file');
- $sheet = $excel->setActiveSheetIndex(0);
- $rownum = 1;
- $list_info = $params['list_info'];
- foreach ($params['columns'] as $key => $column ) {
- $sheet->setCellValue($this->column($key, $rownum), $column['title']);
- if (!(empty($column['width']))) {
- $sheet->getColumnDimension($this->column_str($key))->setWidth($column['width']);
- }
- }
- ++$rownum;
- $len = count($params['columns']);
- foreach ($list as $row ) {
- $i = 0;
- while ($i < $len) {
- $value = ((isset($row[$params['columns'][$i]['field']]) ? $row[$params['columns'][$i]['field']] : ''));
- if(strstr($params['columns'][$i]['field'], 'option_') > -1 && (int)$row['hasoption'] === 1){// 规格有数据
- if(strstr($params['columns'][$i]['field'], 'option_') > -1){// 规格不存在
- $j = 0;
- foreach ($row['option'] as $row_option ) {
- ++$rownum;
- $j = $i;
- while ($j < $len) {
- $excel_option_field = str_replace('option_','',$params['columns'][$j]['field']);
- $value_option = ((isset($row_option[$excel_option_field]) ? $row_option[$excel_option_field] : ''));
- $sheet->setCellValue($this->column($j, $rownum), $value_option);
- ++$j;
- }
- }
- $i = $j;
- }
- }else{
- $sheet->setCellValue($this->column($i, $rownum), $value);
- }
- ++$i;
- }
- ++$rownum;
- }
- $excel->getActiveSheet()->setTitle($params['title']);
- $filename = ($params['title'] . '-' . date('Y-m-d H:i', time()));
- $excel->getActiveSheet()->setTitle($params['title']);
- $filename = ($params['title'] . '-' . date('Y-m-d H:i', time()));
- header('pragma:public');
- header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$params['title'].'.xls"');
- header("Content-Disposition:attachment;filename=".$filename.".xls");
- //attachment新窗口打印inline本窗口打印
- $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
- $objWriter->save('php://output');
- exit;
- }
-
- }
- ?>
|