Heim  >  Artikel  >  Backend-Entwicklung  >  phpexcel倒出带图片excel的宽度设置有关问题

phpexcel倒出带图片excel的宽度设置有关问题

WBOY
WBOYOriginal
2016-06-13 11:59:221453Durchsuche

phpexcel倒出带图片excel的宽度设置问题

elseif (isset($_POST['excel']))
    {
        
        require_once ROOT_PATH.'includes/PHPExcel/PHPExcel.php';
require_once ROOT_PATH.'includes/PHPExcel/PHPExcel/IOFactory.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set properties
$objPHPExcel->getProperties()->setCreator("DizzyLion")
 ->setLastModifiedBy("DizzyLion")
 ->setSubject("Orders output Document");
$filepaths= ROOT_PATH."data/".date("Y-m").'.xls';
$filename = date("Y-m").'.xls';
$rowix = 1;
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$rowix ,  '訂單編號')
            ->setCellValue('B'.$rowix ,  '下單時間')
            ->setCellValue('C'.$rowix ,  '訂單金額')
            ->setCellValue('D'.$rowix ,  '産品圖片')
->setCellValue('E'.$rowix ,  '會員名稱');

$rowix++;
$i=0;
$list = array();
        $order_sn_list = explode(',', $_POST['order_id']);
        foreach ($order_sn_list as $order_sn)
        {
            /* 取得订单信息 */
            $sql = "select pay_name,shipping_name,order_id,order_sn,consignee,address,add_time,tel,mobile,user_name," .
                    "(" . order_amount_field('o.') . ") AS total_fee 
from ".$ecs->table('order_info')." o left join ".$ecs->table('users')." u on o.user_id =
u.user_id where order_sn='$order_sn'";
$row = $db->getRow($sql);
$goods = $db->getAll("select goods_name,goods_id,cgbz,postmsg,goods_number,goods_price,goods_price*goods_number as je,goods_sn from ".$ecs->table('order_goods')." where order_id = '".$row['order_id']."'");
if($goods){
foreach($goods as $k=>$v){
$temp    = array();
$v['img'] = $db->getOne("select goods_thumb from ".$ecs->table('goods')." where goods_id='".$v['goods_id']."'");
$temp['goods'] = $v;
$temp['order_info'] = $row;
$list[$row['order_id']][] = $temp;
}
}
}

foreach ($list as $key => $t) {
foreach($t as $k1=>$value){

$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A'.$rowix ,  $value['order_info']['order_sn'])
            ->setCellValue('B'.$rowix ,  local_date("Y-m-d",$value['order_info']['add_time']))
            ->setCellValue('C'.$rowix ,  $value['order_info']['total_fee'])
            ->setCellValue('E'.$rowix ,  $value['order_info']['user_name']);
$objPHPExcel->getActiveSheet()->getColumnDimension('D'.$rowix)->setAutoSize(true);   
$objPHPExcel->getActiveSheet()->getColumnDimension('D'.$rowix)->setWidth(150); //设置D列,图片列为150的宽度
$objPHPExcel->getActiveSheet()->getRowDimension($rowix)->setRowHeight(80);
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath("../".$value['goods']['img']);
$objDrawing->setHeight(80);
$objDrawing->setCoordinates('D'.$rowix);//图片名称所在的单元格
$objDrawing->getShadow()->setVisible(true);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$rowix++;
}
}
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setAutoSize(true);
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setAutoSize(true);;
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->setTempDir(ROOT_PATH."data");

$objWriter->save($filepaths);

header("Location:../data/".$filename);
exit;

    }
?>

D列是图片显示的内容列,但是我设置了150,可是 程序里面倒出来,还是很窄,没效果
------解决方案--------------------
怎么能删呢?
应写作
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(150);

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn