PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 5, 2022

[FIXED] How to delete hyperlink from cell in phpexcel

 October 05, 2022     php, phpexcel     No comments   

Issue

I am trying to edit a sheet and delete rows, when I do so, the cells with an email address (with a mailto hyperlink) retain the hyperlink although the cell values are replaced by new cell shifting into its place.

For example cell A1 has email address abc@abc.com, cell A2 had a blank cell, when I delete row 1 using $sheet->removeRow fucntion, the row gets deleted, however A1 now is a blank cell with a mailto link to abc@abc.com

I an unable to delete this hyperlink on the cell using phpexcel

I have tried the following

  1. $cell->getHyperlink()->setUrl();
  2. $cell->setHyperlink(new PHPExcel_Cell_Hyperlink(''));

any help would be appreciated


Solution

Pass the value null in to the setHyperlink method against the cell

From looking at the code, this finds the worksheet the cell is attached to and removes the hyperlink if the value is null

$cell->setHyperlink(null);

Worksheet.php https://github.com/PHPOffice/PHPExcel/blob/1.8/Classes/PHPExcel/Worksheet.php#L2702

Cell.php https://github.com/PHPOffice/PHPExcel/blob/1.8/Classes/PHPExcel/Cell.php#L461



Answered By - Brett
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing