PHP匯入Excel檔案技巧講解_PHP教程

來源:互聯網
上載者:User
大家對

PHP匯入Excel檔案程式碼範例如下:

  1. < ?php
  2. require_once '../Excel/reader.php';
  3. // ExcelFile($filename, $encoding);
  4. $data = new Spreadsheet_Excel_Reader();
  5. // Set output Encoding.指定中文碼
  6. $data->setOutputEncoding('gb2312');
  7. /***
  8. * if you want you can change '
    iconv' to mb_convert_encoding:
  9. * $data->setUTFEncoder('mb');
  10. **//***
  11. * By default rows & cols indeces start with 1
  12. * For change initial index use:
  13. * $data->setRowColOffset(0);
  14. **/
  15. /***
  16. * Some function for formatting output.
  17. * $data->setDefaultFormat('%.2f');
  18. * setDefaultFormat - set format for
    columns with unknown formatting
  19. * $data->setColumnFormat(4, '%.3f');
  20. * setColumnFormat - set format for
    column (apply only to number fields)
  21. **/
  22. // 指定讀取的excel檔案
  23. $data->read('../uploads/jsxz01.xls');
  24. /*
  25. $data->sheets[0]['numRows'] - count rows
  26. $data->sheets[0]['numCols'] - count columns
  27. $data->sheets[0]['cells'][$i][$j] - data
    from $i-row $j-column
  28. $data->sheets[0]['cellsInfo'][$i][$j] -
    extended info about cell
  29. $data->sheets[0]['cellsInfo'][$i][$j]['type']
    = "date" | "number" | "unknown"
  30. if 'type' == "unknown" - use 'raw' value,
    because cell contain value with format '0.00';
  31. $data->sheets[0]['cellsInfo'][$i][$j]['raw']
    = value if cell without format
  32. $data->sheets[0]['cellsInfo'][$i][$j]['colspan']
  33. $data->sheets[0]['cellsInfo'][$i][$j]['rowspan']
  34. */
  35. error_reporting(E_ALL ^ E_NOTICE);
  36. // 迴圈讀取每一個單元值
  37. for ($i = 1; $i < = $data->sheets[0]
    ['numRows']; $i++) {
  38. for ($j = 1; $j < = $data->sheets[0]
    ['numCols']; $j++) {
  39. echo """.$data->sheets[0]['cells']
    [$i][$j]."",";
  40. }
  41. echo "< br>";
  42. }
  43. //print_r($data);
  44. //print_r($data->formatRecords);
  45. ?>

希望上面這段PHP匯入Excel檔案的實現代碼可以協助我們對這一知識點有一個深刻的認識。


http://www.bkjia.com/PHPjc/446095.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446095.htmlTechArticle大家對 PHP匯入Excel檔案程式碼範例如下: ?php require_once'../Excel/reader.php'; //ExcelFile($filename,$encoding); $ data = new Spreadsheet_Excel_Reader(); //SetoutputEn...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.