phpexcel 使用getComment获取xls单元格中文批注为乱码
程序员文章站
2022-05-12 21:49:53
...
如题.
表格内容
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值为乱码
回复内容:
如题.
表格内容
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值为乱码
上一篇: Java 实例 - 重载方法异常处理
下一篇: php中 重载(二)