ecshop订单批量导出


20130116160334

ecshop订单批量导出是通过PHPExcel类实现方法,效果见上图:

 

第一步,将PHPExcel类包解压到后台目录。

 

第二步,页面上部署操作按钮:打开admin/templates/order_list.htm文件,在“打印订单”按钮后面(约第73行)加上

 

<input type="submit" value="导出" disabled="true" />

第三步,部署代码:打开admin/order.php文件,在适当位置加上如下代码,(代码就不再一行行解析了,都有注释)

 

/* 批量导出订单 */ elseif (isset($_POST['export'])) {

        if (empty($_POST['order_id'])) {

            sys_msg($_LANG['pls_select_order']);

        }

 

        /* 赋值公用信息 */

        $smarty->assign('shop_name', $_CFG['shop_name']);

        $smarty->assign('shop_url', $ecs->url());

        $smarty->assign('shop_address', $_CFG['shop_address']);

        $smarty->assign('service_phone', $_CFG['service_phone']);

        $smarty->assign('print_time', local_date($_CFG['time_format']));

        $smarty->assign('action_user', $_SESSION['admin_name']);

 

        $html          = '';

        $order_sn_list = explode(',', $_POST['order_id']);

        //////////////////////////  

 

        error_reporting(E_ALL);

 

        date_default_timezone_set('Europe/London');

 

        require_once dirname(__FILE__) . '/Classes/PHPExcel.php';

 

        echo date('H:i:s') . " Create new PHPExcel object\n";

        $objPHPExcel = new PHPExcel();

 

        echo date('H:i:s') . " Set properties\n";

        $objPHPExcel->getProperties()->setCreator("wdz")->setLastModifiedBy("wdz")->setTitle("我的订单")->setSubject("我的订单")->setDescription(date('Y/m/d H:i:s') . "导出的订单")->setKeywords("我的订单")->setCategory("Test result file");

 

        /*设置标题属性*/

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ///////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(40);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ///////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(10);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(10);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(10);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(10);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(40);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('J1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('J1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(15);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('K1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('K1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(15);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('K1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('K1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

        //字体大小

        $objPHPExcel->getActiveSheet()->getStyle('L1')->getFont()->setSize(16);

        //加粗

        $objPHPExcel->getActiveSheet()->getStyle('L1')->getFont()->setBold(true);

        //表格宽度

        $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(15);

        //垂直居中

        $objPHPExcel->getActiveSheet()->getStyle('L1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //水平居中

        $objPHPExcel->getActiveSheet()->getStyle('L1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        ////////////////////

 

        echo date('H:i:s') . " Add some data\n";

        $objPHPExcel->setActiveSheetIndex(0);

        $objPHPExcel->getActiveSheet()->setCellValue('A1', '订货日期');

        $objPHPExcel->getActiveSheet()->setCellValue('B1', '款号');

        $objPHPExcel->getActiveSheet()->setCellValue('C1', '商品名称');

        $objPHPExcel->getActiveSheet()->setCellValue('D1', '属性');

        $objPHPExcel->getActiveSheet()->setCellValue('E1', '数量');

        $objPHPExcel->getActiveSheet()->setCellValue('F1', '价格');

        $objPHPExcel->getActiveSheet()->setCellValue('G1', '收件人');

        $objPHPExcel->getActiveSheet()->setCellValue('H1', '地址');

        $objPHPExcel->getActiveSheet()->setCellValue('I1', '电话');

        $objPHPExcel->getActiveSheet()->setCellValue('J1', '邮箱');

        $objPHPExcel->getActiveSheet()->setCellValue('K1', '发货日期');

 

        $hang = 2;

        ///////////////////////  

        foreach ($order_sn_list as $order_sn) {

            /* 取得订单信息 */

            $order = order_info(0, $order_sn);

            if (empty($order)) {

                continue;

            }

 

            /* 根据订单是否完成检查权限 */

            if (order_finished($order)) {

                if (!admin_priv('order_view_finished', '', false)) {

                    continue;

                }

            } else {

                if (!admin_priv('order_view', '', false)) {

                    continue;

                }

            }

 

            /* 如果管理员属于某个办事处,检查该订单是否也属于这个办事处 */

            $sql       = "SELECT agency_id FROM " . $ecs->table('admin_user') . " WHERE user_id = '$_SESSION[admin_id]'";

            $agency_id = $db->getOne($sql);

            if ($agency_id > 0) {

                if ($order['agency_id'] != $agency_id) {

                    continue;

                }

            }

 

            /* 取得用户名 */

            if ($order['user_id'] > 0) {

              &n