首页 >后端开发 >php教程 >phpexcel 使用getComment获取xls单元格中文批注为乱码

phpexcel 使用getComment获取xls单元格中文批注为乱码

WBOY
WBOY原创
2016-07-06 13:51:581339浏览

如题.
phpexcel 使用getComment获取xls单元格中文批注为乱码
表格内容

<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值为乱码

回复内容:

如题.
phpexcel 使用getComment获取xls单元格中文批注为乱码
表格内容

<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值为乱码

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn