Home > Backend Development > PHP Tutorial > phpexcel uses getComment to get Chinese comments in xls cells as garbled characters

phpexcel uses getComment to get Chinese comments in xls cells as garbled characters

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:51:58
Original
1351 people have browsed it

As title.
phpexcel uses getComment to get Chinese comments in xls cells as garbled characters
Table content

<code>include_once('includes/PHPExcel.php');
$uploadfile = xxx;
$type = strtolower( pathinfo($uploadfile, PATHINFO_EXTENSION) );
if ($type == 'xls' || $type == 'xlsx') {
    $objPHPExcel = PHPExcel_IOFactory::load($uploadfile)
} else if ($type == 'csv') {
    $objReader = PHPExcel_IOFactory::createReader('CSV')
        ->setDelimiter(',')
        ->setInputEncoding('GBK') //不设置将导致中文列内容返回boolean(false)或乱码
        ->setEnclosure('"')
        ->setLineEnding("\r\n")
        ->setSheetIndex(0);
    $objPHPExcel = $objReader->load($uploadfile);
}

$sheet = $objPHPExcel->getSheet(0);
$plaintext = $sheet->getComment("A1");
echo $plaintext;</code>
Copy after login
Copy after login

$plaintext value is garbled

Reply content:

As title.
phpexcel uses getComment to get Chinese comments in xls cells as garbled characters
Table content

<code>include_once('includes/PHPExcel.php');
$uploadfile = xxx;
$type = strtolower( pathinfo($uploadfile, PATHINFO_EXTENSION) );
if ($type == 'xls' || $type == 'xlsx') {
    $objPHPExcel = PHPExcel_IOFactory::load($uploadfile)
} else if ($type == 'csv') {
    $objReader = PHPExcel_IOFactory::createReader('CSV')
        ->setDelimiter(',')
        ->setInputEncoding('GBK') //不设置将导致中文列内容返回boolean(false)或乱码
        ->setEnclosure('"')
        ->setLineEnding("\r\n")
        ->setSheetIndex(0);
    $objPHPExcel = $objReader->load($uploadfile);
}

$sheet = $objPHPExcel->getSheet(0);
$plaintext = $sheet->getComment("A1");
echo $plaintext;</code>
Copy after login
Copy after login

$plaintext value is garbled

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template