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
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-06 13:51:581346browse

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>

$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>

$plaintext value is garbled

Statement:
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