G
G
gpfspam2015-11-30 14:39:26
phpspreadsheet
gpfspam, 2015-11-30 14:39:26

How to remove/overwrite a comment in a PHPExcel cell?

Good afternoon!
I use PHPExcel to work with Excel.
It is necessary to overwrite the comment in the cell, but it turns out only to append to the end with this code:

$objPHPExcel = PHPExcel_IOFactory::load('./test.xlsx');
$objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun("testtesttest"); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
$objWriter->save('./test.xlsx');

How all the same to overwrite or delete the comment in the necessary cell?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-11-30
@gpfspam

You need to use the setText() method :

$objPHPExcel = PHPExcel_IOFactory::load('./test.xlsx');
$comment = $objPHPExcel->getActiveSheet()->getComment('E11');
$commentText = new PHPExcel_RichText;
$commentText->createText("testtesttest");
$comment->setText($commentText);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
$objWriter->save('./test.xlsx');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question