首頁 >後端開發 >php教程 >phpexcel 使用getComment获取xls单元格中文批注为乱码

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-07-06 13:51:581346瀏覽

如题.
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