search
Homephp教程php手册PHP导入Excel文件技巧讲解

PHP导入Excel文件技巧讲解

Jun 13, 2016 am 11:10 AM
excelphpcoderightimportSkilldocumentExampleexplain

大家对

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文件的实现代码可以帮助我们对这一知识点有一个深刻的认识。


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools