PHP Excel file import tips _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags php excel
PHP Excel file import tips. The following is an example of the PHP Excel file import code :? Phprequire_once... Excelreader. php; ExcelFile ($ filename, $ encoding); $ datanewSpreadsheet_Excel_Reader (); SetoutputEn

An example of PHP Excel file import code is 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 the Chinese code
  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
    Columns with unknown formatting
  19. * $ Data->SetColumnFormat (4, '%. 3f ');
  20. * SetColumnFormat-set format
    Column (apply only to number fields)
  21. **/
  22. // Specify the excel file to be 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. // Read each unit value cyclically
  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. ?>

We hope that the above PHP import Excel file implementation code can help us have a deep understanding of this knowledge point.


Example code for importing an Excel file in PHP :? 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.