PHP Spreadsheet_Excel_Reader: garbled Chinese characters imported into excel

Source: Internet
Author: User
Tags php class

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.

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.