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

Wednesday, October 5, 2022

[FIXED] What can you use instead of tick marks ' in PHP?

 October 05, 2022     cell, excel, formulas, php, phpexcel     No comments   

Issue

I am trying to set the value of a cell in an Excel spreadsheet to a formula that references a worksheet and has several parameters to it. My formula is:

=SUMIFS('Sheet1'!AY:AY,'Sheet1'!J:J, "Q1", 'Sheet1'!M:M, "Extensions", 'Sheet1'!AW:AW, "NP")+SUMIFS('Sheet1'!AY:AY,'Sheet1'!J:J, "Q1", 'Sheet1'!M:M, "Extensions", 'Sheet1'!AW:AW, "PHBO")+SUMIFS('Sheet1'!AY:AY,'Shee1'!J:J, "Q1", 'Sheet1'!M:M, "Extensions", 'Sheet1'!AW:AW, "PR", 'Sheet1'!AN:AN, "Both")+SUMIFS('Sheet1'!AY:AY,'Sheet1'!J:J, "Q1", 'Sheet1'!M:M, "Extensions", 'Sheet1'!AW:AW, "PR", 'Sheet1'!AN:AN, "Area")

My PHP is:

$objPHPExcel->setActiveSheetIndex(1)
            ->setCellValue('B2', 'XXX');

Where XXX = the formula above. The problem is because of the ' and " marks in the formula I get errors.


Solution

<?PHP
$stmt = <<<EOF
=SUMIFS('Sheet1'!AY:AY,'Sheet1'!J:J, "Q1", 'Sheet1'!M:M, "Extensions", 'Sheet1'!AW:AW, "NP")+SUMIFS('Sheet1'!AY:AY,'Sheet1'!J:J, "Q1", 'Sheet1'!M:M, "Extensions", 'Sheet1'!AW:AW, "PHBO")+SUMIFS('Sheet1'!AY:AY,'Shee1'!J:J, "Q1", 'Sheet1'!M:M, "Extensions", 'Sheet1'!AW:AW, "PR", 'Sheet1'!AN:AN, "Both")+SUMIFS('Sheet1'!AY:AY,'Sheet1'!J:J, "Q1", 'Sheet1'!M:M, "Extensions", 'Sheet1'!AW:AW, "PR", 'Sheet1'!AN:AN, "Area")
EOF;

$objPHPExcel->setActiveSheetIndex(1)
        ->setCellValue('B2', $stmt);
?>

Assigns your String to the variable $stmt then uses that variable in your function. This allows for the ' and " to be read as characters in the string instead of being read by the interpreter to break the sting.



Answered By - Sparky
Answer Checked By - Robin (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