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:
- <? Php
- Require_once '../Excel/reader. php ';
- // ExcelFile ($ filename, $ encoding );
- $ Data = new Spreadsheet_Excel_Reader ();
- // Set output Encoding. specify the Chinese code
- $ Data->SetOutputEncoding ('gb2312 ');
- /***
- * If you want you can change'
Iconv 'to mb_convert_encoding:
- * $ Data->SetUTFEncoder ('mb ');
- **//***
- * By default rows & cols indeces start with 1
- * For change initial index use:
- * $ Data->SetRowColOffset (0 );
- **/
- /***
- * Some function for formatting output.
- * $ Data->SetDefaultFormat ('%. 2f ');
- * SetDefaultFormat-set format
Columns with unknown formatting
- * $ Data->SetColumnFormat (4, '%. 3f ');
- * SetColumnFormat-set format
Column (apply only to number fields)
- **/
- // Specify the excel file to be read
- $ Data->Read ('../uploads/jsxz01.xls ');
- /*
- $ Data->Sheets [0] ['numrows ']-count rows
- $ Data->Sheets [0] ['numcols']-count columns
- $ Data->Sheets [0] ['cells '] [$ I] [$ j]-data
From $ I-row $ j-column
- $ Data->Sheets [0] ['cellsinfo'] [$ I] [$ j]-
Extended info about cell
- $ Data->Sheets [0] ['cellsinfo'] [$ I] [$ j] ['type']
= "Date" | "number" | "unknown"
- If 'type' = "unknown"-use 'raw' value,
Because cell contain value with format '0. 00 ';
- $ Data->Sheets [0] ['cellsinfo'] [$ I] [$ j] ['raw']
= Value if cell without format
- $ Data->Sheets [0] ['cellsinfo'] [$ I] [$ j] ['colspan ']
- $ Data->Sheets [0] ['cellsinfo'] [$ I] [$ j] ['rowspan ']
- */
- Error_reporting (E_ALL ^ E_NOTICE );
- // Read each unit value cyclically
- For ($ I = 1; $ I<= $ Data->Sheets [0]
['Numrows ']; $ I ++ ){
- For ($ j = 1; $ j<= $ Data->Sheets [0]
['Numcols']; $ j ++ ){
- Echo ". $ data->Sheets [0] ['cells]
[$ I] [$ j]. "", ";
- }
- Echo"< Br>";
- }
- // Print_r ($ data );
- // Print_r ($ data->FormatRecords );
- ?>
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...