This article to introduce PHP Spreadsheet_excel_reader import Excel Chinese display garbled and can not read. xlsx format of the file, there are students who encounter such problems can enter the reference.
Spreadsheet_excel_reader is a common PHP class for importing Excel files.
Normal use of this class to import Excel code is as follows
| The code is as follows |
Copy Code |
|
Introduce system public files.
Require_once ('.. /global.php ');
Introducing the Excel Read function class
Require_once ('./excel/reader.php ');
Instantiation of
$data = new Spreadsheet_excel_reader ();
Set Output type (can be "GBK" or "UTF-8"), note the encoding conversion when inserting a database
$data->setoutputencoding (' CP936 ');
Read Excel file Address
$data->read (' 20110630_ctms.xls ');
Print output sheet array, single or multiple
Print_r ($data->sheets);
Echo '
';
Print out the number of lines per sheet, $k zero-based
$k = 0;
echo $data->sheets[$k [' numrows ']; |
When using this class, I have encountered the following problem.
1. Cannot read. xlsx-formatted files.
The. xlsx format file cannot be read directly, and the workaround is to open the file and then save it as an. xls file.
Note: Select Microsoft Excel 5.0/95 Workbook (*.xls). This is more useful.
"Excel 97-2003 Workbook (*.xls)" This is OK, but sometimes there are problems, such as reading into the data loss phenomenon.
2. Coding issues. Chinese display garbled.
$data->setoutputencoding (' cp936′) is used to set the output encoding, but it is not possible to output the desired encoding arbitrarily. You can try to change it into GBK or utf-8 and convert it with Iconv.
http://www.bkjia.com/PHPjc/632103.html www.bkjia.com true http://www.bkjia.com/PHPjc/632103.html techarticle this article to introduce PHP Spreadsheet_excel_reader import Excel Chinese display garbled and can not read. xlsx format of the file, there are students who encounter such problems can enter the reference. ...