Home php教程 PHP源码 PHPExcel code

PHPExcel code

Nov 08, 2016 pm 05:26 PM

vendor("PHPExcel176.PHPExcel");
        // Create new PHPExcel object
        $objPHPExcel = new PHPExcel();
        // Set properties
        $objPHPExcel->getProperties()->setCreator("ctos")
            ->setLastModifiedBy("ctos")
            ->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("Test result file");
        //set width
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(80);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(80);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(80);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(80);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(80);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(80);
        //设置行高度
        //$objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
        //$objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
        //set font size bold
        $objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10);
        //$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getFont()->setBold(true);
        //$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
        //设置水平居中
        //$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //合并cell
        //$objPHPExcel->getActiveSheet()->mergeCells('A1:F1');
        //set font size bold
        //$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10);
        //$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getFont()->setBold(true);
        //$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);����ˮƽ����
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //�ϲ�cell
        $objPHPExcel->getActiveSheet()->mergeCells('A1:F1');
        // set table header content
        $objPHPExcel->setActiveSheetIndex(0)
           ->setCellValue('A1', iconv("utf-8","gb2312","订单数据汇总  时间:'.date('Y-m-d H:i:s')"))
            ->setCellValue('A2', iconv("utf-8","gb2312","订单ID"))
            ->setCellValue('B2', iconv("utf-8","gb2312","下单人"))
            ->setCellValue('C2', iconv("utf-8","gb2312","客户名称"))
            ->setCellValue('D2', iconv("utf-8","gb2312","下单时间"))
            ->setCellValue('E2', iconv("utf-8","gb2312","需求机型"))
            ->setCellValue('F2', iconv("utf-8","gb2312","需求数量"));
        // Miscellaneous glyphs, UTF-8
      for($i=0;$i<count($OrdersData)-1;$i++){
            $objPHPExcel->getActiveSheet(0)->setCellValue(&#39;A&#39;.($i+3),  iconv("utf-8","gb2312",$OrdersData[$i][&#39;id&#39;]));
            $objPHPExcel->getActiveSheet(0)->setCellValue(&#39;B&#39;.($i+3),  iconv("utf-8","gb2312",$OrdersData[$i][&#39;reid&#39;]));
            $objPHPExcel->getActiveSheet(0)->setCellValue(&#39;C&#39;.($i+3),  iconv("utf-8","gb2312",$OrdersData[$i][&#39;topid&#39;]));
            //$objPHPExcel->getActiveSheet(0)->setCellValue(&#39;D&#39;.($i+3), iconv(&#39;utf-8&#39;,&#39;gb2312&#39;,toDate($OrdersData[$i][&#39;typename&#39;]))); //���������common.php������
            $objPHPExcel->getActiveSheet(0)->setCellValue(&#39;D&#39;.($i+3),  iconv("utf-8","gb2312",$OrdersData[$i][&#39;typename&#39;]));
            $objPHPExcel->getActiveSheet(0)->setCellValue(&#39;E&#39;.($i+3),  iconv("utf-8","gb2312",$OrdersData[$i][&#39;typelink&#39;]));
            $objPHPExcel->getActiveSheet(0)->setCellValue(&#39;F&#39;.($i+3),  iconv("utf-8","gb2312",$OrdersData[$i][&#39;keyword&#39;]));
            //$objPHPExcel->getActiveSheet()->getStyle(&#39;A&#39;.($i+3).&#39;:F&#39;.($i+3))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
            //$objPHPExcel->getActiveSheet()->getStyle(&#39;A&#39;.($i+3).&#39;:F&#39;.($i+3))->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
            //$objPHPExcel->getActiveSheet()->getRowDimension($i+3)->setRowHeight(16);
        }
        //  sheet
        $objPHPExcel->getActiveSheet()->setTitle( iconv("utf-8","gb2312",&#39;订单汇总表&#39;));
        // Set active sheet index to the first sheet, so Excel opens this as the first sheet
        $objPHPExcel->setActiveSheetIndex(0);
        // excel头参数
        header(&#39;Content-Type: application/vnd.ms-excel; charset=utf-8&#39;);
        header(&#39;Content-Type: application/force-download&#39;);
        header(&#39;Content-Type: application/octet-stream&#39;);
        header(&#39;Content-Type: application/download&#39;);
        //header(&#39;Content-type:charset=utf-8);
        //header(&#39;Content-Transfer-Encoding: utf-8&#39;);
        header(&#39;Content-Disposition: attachment;filename=&#39;.iconv("utf-8","gb2312","订单汇总".date(&#39;Ymd-His&#39;).".xls"));  //日期为文件名后缀
        //header(&#39;Cache-Control: max-age=0&#39;);
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, &#39;excel5&#39;);  //excel5为xls格式,excel2007为xlsx格式
        $objWriter->save(&#39;php://output&#39;);
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)