Spreadsheet_Excel_Reader is a common php class for importing excel files.
Under normal circumstances, use this class to import the excel code as follows:
The code is as follows: |
Copy code |
<? Php // Introduce public system files. Require_once ('../global. Php '); // Introduce the excel reading function Require_once ('./excel/reader. Php '); // Instantiate $ Data = new Spreadsheet_Excel_Reader (); // Set the output type (can be "GBK" or "UTF-8"), pay attention to the encoding conversion when inserting the database $ Data-> setOutputEncoding ('cp936 '); // Read the excel file address $ Data-> read('10651130_ctms.xls '); // Print the output sheet array, one or more Print_r ($ data-> sheets ); Echo '<br/> '; // Print the number of rows for each sheet. $ k starts from scratch. $ K = 0; Echo $ data-> sheets [$ k] ['numrows ']; |
When using this class, I encountered the following problems.
1.xlsx files cannot be read.
. Xlsxformat files cannot be directly read. The file is opened, and the file is named. Xls.
Note: Select "Microsoft Excel 5.0/95 (*. xls )". This is easy to use.
"Excel 97-2003 thin (*. xls)" is also acceptable, but sometimes there are problems, such as data loss.
2. Encoding problems. Garbled characters are displayed in Chinese.
$ Data-> setOutputEncoding ('cp936 & prime;); is used to set the output encoding, but cannot output the desired encoding at will. You can try to change it to gbk or UTF-8 and then use iconv to convert it.