doudanglang5826 2012-08-08 16:09
浏览 18
已采纳

如何以编程方式检索excel中的单元格注释?

I recently imported a number of large excel 2010 spreadsheets (which was exported to CSV for the import) into a database. I have now been told that the cell comments are missing (I didn't even know there were cell comments in the original Excel file, I only ever had the CSV).

I need to search each row of the Excel file, find cells with cell comments, grab the comment and add it into the database for that row (the database references the row number from the spreadsheet, so if I can just extract row number and all the cell comments in that row, that's perfect)

My skills are in PHP and Perl. Ideally I would use PHP to read and process the data, but using something else to output text/csv, which I can then parse with PHP would work fine too.

Does anyone know a way to extract these cell comments, or have any pointers?

Thanks!

  • 写回答

2条回答 默认 最新

  • douxu0550 2012-08-08 16:25
    关注

    Use the PHPExcel library. Comments are held against the worksheet. and the worksheet's getComments() method will return an array of comment objects indexed by their cell address.

    EDIT

    include '/PHPExcel_Library/Classes/PHPExcel.php';
    
    $inputFileType = 'Excel5';
    $inputFileName = 'CS2template_all_products_v12.xls';
    
    $objPHPExcelReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objPHPExcelReader->load($inputFileName);
    
    $sheet = $objPHPExcel->getActiveSheet();
    
    $comments = $sheet->getComments();
    foreach($comments  as $cellID => $comment) {
        echo $cellID,PHP_EOL;
        var_dump($comment->getText()->getPlainText());
    }
    

    Note, my example uses an Excel .xls file, but the method will work just as easily replacing the $inputFileType with "Excel2007" for an .xlsx file

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn