php获取excel所有的批注

时间:2023-05-18 18:33:32

phpexcel下载:https://github.com/PHPOffice/PHPExcel

<?php
/**
*获取excel所有的批注
*
* 存在编码问题,xls和xlsx的批注编码不同,建议使用xlsx文件格式
*/ /** Include PHPExcel_IOFactory */
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php'; $inputFileName = "file.xlsx"; if (!file_exists($inputFileName)) {
exit("not found $inputFileName." . EOL);
} $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName); // 获取所有批注
$objSheel = $objPHPExcel->getSheet();
$comments = $objSheel->getComments();//所有的批注
foreach ($comments as $pCellCoordinate => $comment) {
$cell_value = $objSheel->getCell($pCellCoordinate)->getValue();
$comment_value = $comment->getText()->getPlainText(); // $cell_value = iconv('gbk', 'utf-8', $cell_value);
// $comment_value = iconv('gbk', 'utf-8', $comment_value); var_dump($cell_value);
var_dump($comment_value);
}