php讀取excel檔案

來源:互聯網
上載者:User
<form id="form1" name="form1" method="post" action="">    <label>        <input name="file1" type="file" id="file1" />        <input type="submit" name="Submit1" value="提交" />    </label></form><p><?php/*到 http://sourceforge.net/projects/phpexcelreader/ 下載 phpExcelReader壓縮包裡的 Excel 檔案夾裡有兩個檔案 oleread.inc reader.php將 oleread.inc 重新命名為 OLERead.php將 reader.php 檔案中 require_once 'Spreadsheet/Excel/Reader/OLERead.php'; 替換成 require_once 'OLERead.php';將 reader.php 檔案中 $this->_ole =& new OLERead(); 替換成 $this->_ole = new OLERead();*/require_once 'Excel/reader.php';//需要讀取 excel 的頁面引用 reader.php 檔案$excel_data = new Spreadsheet_Excel_Reader ();//執行個體化一個讀取excel對象$excel_data->setOutputEncoding ( 'utf-8' );//賦編碼格式//串連資料庫$conn = mysql_connect ( 'localhost', 'root', 'root' ) or die ( "Can not connect to database." );mysql_query ( "set names 'utf-8'" );mysql_select_db ( 'test' );if ($_POST ['Submit1']) {    $excel_data->read ( $_POST ['file1'] );//為讀取excel對象賦一個要讀取的檔案    //$excel_data->read ( "aaa.xls" );//如非提交檔案也可直接賦檔案路徑    for($i = 1; $i <= $excel_data->sheets [0] ['numRows']; $i ++) {        //$id = $excel_data->sheets [0] ['cells'] [$i] [1];//sheets [0] 是excel檔案中第一頁,$i 第幾行,1第一列,頁索引從0開始,行,列索引都從1開始        $title = $excel_data->sheets [0] ['cells'] [$i] [2];//第一頁,第$i行,第2列        $content = $excel_data->sheets [0] ['cells'] [$i] [3];        $ins_message = "INSERT INTO message( title , content ) VALUES( '$title' , '$content' )";        $que_message = mysql_query ( $ins_message );    }}/*excel中 工具->選項->常規 選中 R1C1引用樣式 可使 列名由字母變為數字*/?>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.