欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-12 21:49:53
...

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

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;

$plaintext值为乱码

回复内容:

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

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;

$plaintext值为乱码

相关标签: php phpexcel