Everyone to
Examples of PHP import Excel file code are as follows:
- < ? PHP
- Require_once '. /excel/reader.php ';
- Excelfile ($filename, $encoding);
- $ Data = New Spreadsheet_excel_reader ();
- Set output Encoding. Specify Chinese code
- $data- > setoutputencoding (' gb2312 ');
- /***
- * If you want your 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 for
Columns with unknown formatting
- * $data- > Setcolumnformat (4, '%.3f ');
- * Setcolumnformat-set format for
Column (apply only to number fields)
- **/
- Specify the Excel file to 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);
- Iterate through each cell value
- 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);
- ?>
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 ...