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

Heim php教程 PHP源碼 PHP excel讀取excel文件轉(zhuǎn)換為數(shù)組

PHP excel讀取excel文件轉(zhuǎn)換為數(shù)組

May 25, 2016 pm 04:59 PM

php代碼

/*
* 將excel轉(zhuǎn)換為數(shù)組 by aibhsc
* */
require(ROOT_PATH . 'includes/PHPExcel.php');//引入PHP EXCEL類(lèi)
function format_excel2array($filePath='',$sheet=0){
        if(empty($filePath) or !file_exists($filePath)){die('file not exists');}
        $PHPReader = new PHPExcel_Reader_Excel2007();        //建立reader對(duì)象
        if(!$PHPReader->canRead($filePath)){
                $PHPReader = new PHPExcel_Reader_Excel5();
                if(!$PHPReader->canRead($filePath)){
                        echo 'no Excel';
                        return ;
                }
        }
        $PHPExcel = $PHPReader->load($filePath);        //建立excel對(duì)象
        $currentSheet = $PHPExcel->getSheet($sheet);        //**讀取excel文件中的指定工作表*/
        $allColumn = $currentSheet->getHighestColumn();        //**取得最大的列號(hào)*/
        $allRow = $currentSheet->getHighestRow();        //**取得一共有多少行*/
        $data = array();
        for($rowIndex=1;$rowIndex<=$allRow;$rowIndex++){        //循環(huán)讀取每個(gè)單元格的內(nèi)容。注意行從1開(kāi)始,列從A開(kāi)始
                for($colIndex=&#39;A&#39;;$colIndexgetCell($addr)->getValue();
                        if($cell instanceof PHPExcel_RichText){ //富文本轉(zhuǎn)換字符串
                                $cell = $cell->__toString();
                        }
                        $data[$rowIndex][$colIndex] = $cell;
                }
        }
        return $data;
}


使用方法:
                        $filePath = ROOT_PATH.&#39;data/diamondStock.xlsx&#39;;        //鉆石庫(kù)存文件
                        $data = format_excel2array($filePath);
                        print_r($data);die;

輸出結(jié)果示例:

Array
(
    [1] => Array
        (
            [A] => 商品編號(hào)
            [B] => 商品名稱(chēng)
            [C] => 總重量
            [D] => 進(jìn)貨價(jià)格
            [E] => 銷(xiāo)售價(jià)格
            [F] => 4C備注
        )

    [2] => Array
        (
            [A] => 10001
            [B] => GIA-2156685995
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [3] => Array
        (
            [A] => 10002
            [B] => GIA-2156685996
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [4] => Array
        (
            [A] => 10003
            [B] => GIA-2156685997
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [5] => Array
        (
            [A] => 10004
            [B] => GIA-2156685998
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [6] => Array
        (
            [A] => 10005
            [B] => GIA-2156685999
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [7] => Array
        (
            [A] => 10006
            [B] => GIA-2156686000
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [8] => Array
        (
            [A] => 10007
            [B] => GIA-2156686001
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [9] => Array
        (
            [A] => 10008
            [B] => GIA-2156686002
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [10] => Array
        (
            [A] => 10009
            [B] => GIA-2156686003
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [11] => Array
        (
            [A] => 10010
            [B] => GIA-2156686004
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [12] => Array
        (
            [A] => 10011
            [B] => GIA-2156686005
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [13] => Array
        (
            [A] => 10012
            [B] => GIA-2156686006
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

    [14] => Array
        (
            [A] => 10013
            [B] => GIA-2156686007
            [C] => 0.7
            [D] => 1760
            [E] => 1848
            [F] => G色、0.7ct、SI1、FR
        )

)

Erkl?rung dieser Website
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

Hei?e KI -Werkzeuge

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem v?llig kostenlosen KI-Gesichtstausch-Tool aus!

Hei?e Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Hei?e Themen

PHP-Tutorial
1502
276