国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP源碼 Using the PHPExcel library

Using the PHPExcel library

Nov 09, 2016 pm 02:46 PM

/**
 * excel 寫入,基于PHPExcel庫
 * @param array $data
 * @param $file
 * @return bool
 * @throws PHPExcel_Exception
 *
 */
function excel_insert(array $data,$file){
 
//    $data = [
//        '庫房'=>[
//            ['庫房編號','庫房名詞',1],
//            ['庫房編號','庫房名詞',1],
//            ['庫房編號','庫房名詞',1],
//            ['庫房編號','庫房名詞',1],
//            ['庫房編號','庫房名詞',1],
//        ],
//        '庫房2'=>[
//            ['庫房編號','庫房名詞',1],
//            ['庫房編號','庫房名詞',1],
//            ['庫房編號','庫房名詞',1],
//            ['庫房編號','庫房名詞',1],
//            ['庫房編號','庫房名詞',1],
//        ],
//    ];
//    excel_insert($data,'s.xlsx');
 
    if(!$data||!$file){
        return false;
    }
 
    $sheet_id = 0;
    //創(chuàng)建excel操作對象
    $objPHPExcel = new PHPExcel();
    //獲得文件屬性對象,給下文提供設(shè)置資源
    $objPHPExcel->getProperties()->setCreator("綿陽市碳素云信息技術(shù)有限責(zé)任公司")
        ->setLastModifiedBy("綿陽市碳素云信息技術(shù)有限責(zé)任公司")
        ->setTitle("Input_Goods_message")
        ->setSubject("主題1")
        ->setDescription("隨便一個描述了")
        ->setKeywords("關(guān)鍵字 用空格分開")
        ->setCategory("分類 ");
    for($i=1;$i<count($data);$i++){
        $objPHPExcel->addSheet(new PHPExcel_Worksheet($objPHPExcel,&#39;sheet&#39;.$i));
    }
    foreach($data as $sheetName => $sheetData){
        $Sheet = $objPHPExcel->setActiveSheetIndex($sheet_id);
        $Sheet->setTitle($sheetName);
        $insert_id = 1;
        foreach($sheetData as $rowData){
            if(is_array($rowData)&&$rowData){
                foreach($rowData as $id => $cellData){
                    if(is_numeric($id)&&(is_string($cellData)||is_numeric($cellData))){
                        $Sheet->setCellValue(chr(65+$id).$insert_id,$cellData);
                    }else{
                        return false;
                    }
                }
                $insert_id++;
            }else{
                return false;
            }
        }
        $sheet_id++;
    }
    try{
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, &#39;Excel2007&#39;);
        $objWriter->save($file);
    }catch (Exception $e){
        return false;
    }
}

How to use:

$data = [
        &#39;庫房&#39;=>[
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
        ],
        &#39;庫房2&#39;=>[
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
            [&#39;庫房編號&#39;,&#39;庫房名詞&#39;,1],
        ],
    ];
    excel_insert($data,&#39;s.xlsx&#39;);


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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)