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

Tuesday, October 4, 2022

[FIXED] How to get Named Ranges in PHPSpreadsheet

 October 04, 2022     php, phpexcel, phpspreadsheet     No comments   

Issue

I want get named ranges in my file. just name of my ranges. in my file, i have ranges 'detail', 'header', 'footer'. this is my function

$temp_name = [];
foreach($spreadsheet->getNamedRanges() as $name){
   $temp_name [] = $name;
}
print_r("<br>Temp Name<br>");
print_r($temp_name[]);
print_r("<br><br>");

but i get so many value in $temp_name.


Solution

I don't use PhpSpreadsheet, but looking at their documentation, getNamedRanges returns an array of NamedRanges, which in turn have names, it doesn't return just names alone. So you need to get the name from the range, like -

foreach ($spreadsheet->getNamedRanges() as $range) {
    temp_name[] = $range->getName();
}

also re: print_r("<br>Temp Name<br>"); for strings, just use print '..';, print_r() is for arrays.



Answered By - gingerCodeNinja
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

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