php获取excel所有的批注

本文介绍如何使用PHPExcel库从Excel文件中读取所有的批注信息,并提供了完整的PHP代码示例。注意不同文件格式(如xls与xlsx)的编码差异可能导致的问题。

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);
}

 

转载于:https://www.cnblogs.com/yingww/p/5861524.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值