PHP Import Excel file Tips _php Tutorial

Source: Internet
Author: User
Everyone to

Examples of PHP import Excel file code are as follows:

  1. < ? PHP
  2. Require_once '. /excel/reader.php ';
  3. Excelfile ($filename, $encoding);
  4. $ Data = New Spreadsheet_excel_reader ();
  5. Set output Encoding. Specify Chinese code
  6. $data- > setoutputencoding (' gb2312 ');
  7. /***
  8. * If you want your 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. Specify the Excel file to read
  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. Iterate through each cell value
  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. ?>

Hope that the above PHP import Excel file Implementation code can help us to this knowledge point has a deep understanding.


http://www.bkjia.com/PHPjc/446095.html www.bkjia.com true http://www.bkjia.com/PHPjc/446095.html techarticle Examples of PHP import Excel file code are as follows: Php require_once '. /excel/reader.php '; Excelfile ($filename, $encoding); $ data = new Spreadsheet_excel_reader (); Setoutputen ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.