PHP spreadsheet_excel_reader Import Excel Chinese display garbled _php tutorial

Source: Internet
Author: User
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. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.