I have a cell in an excel sheet that i am trying to read.
When I use the function getCalculatedValue it's throwing following error:
Financials!LU83 -> Financials!LU81 -> Formula Error: An unexpected error occured
I wrote following function to read from a cell
private function getCellValue($data)
{
//example of data variable
//$data = [0, 'G79'];
$excel = $this->excel;
$excel->setActiveSheetIndex($data[0]);
\PHPExcel_Calculation::getInstance($excel)->flushInstance();
\PHPExcel_Calculation::getInstance($excel)->clearCalculationCache();
return $excel->getActiveSheet()->getCell($data[1])->getCalculatedValue();
}
that cell that I am trying to read has following value
=LU83+LT84
where LU83 has following value
=LU73-SUM(LU76:LU81)
LU81 has value
=VLOOKUP(LU8,'Wiser Return'!$O:$S,5,0)
I have no idea why I am getting this error. I wish there was a way to debug? Is there a way?
Any help is appreciated.
Thanks
The problem is that PHPExcel's calculation engine does not fully support row or column ranges.
=VLOOKUP(LU8,'Wiser Return'!$O:$S,5,0)
contains the column range $O:$S
If this can be converted to a cell range instead, e.g
=VLOOKUP(LU8,'Wiser Return'!$O1:$S1024,5,0)
then it should handle the formula correctly
I can't comment now, but I found some link that might help you.
In this question the accepted answer states, that you can get further information about the error with this gist.
(I suggest deleting your question if this helped you.)
Related
I copied this code from PhpSpreadsheet's documentation and it does not work.
This example can be found on this page:
LINK to PhpSpreadsheet's documentation
From the above link
My code:
$sheet->getCell('A2')->setValue(19);
$sheet->getStyle('A2')->getNumberFormat()->setFormatCode('0000');
// will show as 0019 in Excel
But its not working and this is the result:
The expected value of cell $A2 should be 0019 but it shows 19.
Any idea on how to fix this?
Maybe you use a CSV format try to use Xlsx, I think styling in CSV is not working.
I think this is already issued and there's no solution yet. I'm also looking for the solution but the solution i only found is not use CSV.
https://github.com/PHPOffice/PhpSpreadsheet/issues/2230
I need to do a report sing php & pdf based on another coder's(asp) data in mysql.
$Mysqldata_Field1:[{"name":"alex","age":"30","pic":"filename.ext"}, {"name":"alice","age":"29","pic":"filename.ext"}]
I need to extract all the "pic" value from the array above which is stored in mysql.
What is the best approach?
I have tried this
$img=json_decode($Mysqldata_Field1,true);
foreach($img as $item=>$pic)
{
$images .= $pic["pic"].",";
}
But I'm getting error:
Invalid argument supplied for foreach()
Thanks to both the suggestion.
var_dump showed that the $mysqldata_Field1 contains both array for some records and some strings (incomplete array).
managed to correct those data entry to make a complete array, then the script worked.
this time its not the code issue, its the data entry.
I'm trying to assign the value =FALSE to a cell in Excel using a "Button". The macro for the button is the following:
function_TEST_Click(){
Sheet("Sheet1").Range("J5").Value="=FALSE"
}
When I click the button I get the following error:
Error in PHP macro.
Code: M0 - PHP Parse error: syntax error, unexpected '=' in Module1 on line 3
Could you guys let me know what am I doing wrong? Please have in mind that this is my first question on stackoverflow and I'm not familiar with Excel VBA, neither with PHP Macros.
Value expects a value, you're trying to enter a formula. Either
Sheet("Sheet1").Range("J5").Value= FALSE
or
Sheet("Sheet1").Range("J5").Formula ="=FALSE"
I need PHPExcel to sum fields form G31 to field upon my total field (G-the-number-depends).
A formula
=SUM(G31:INDIRECT(ADDRESS(ROW()-1;COLUMN())))
which normally works, when passed to PHPExcel changes on the output into
=SUM(INDIRECT(ADDRESS(ROW()-1;COLUMN())&": G31"))
which doesn't.
My syntax in PHPExcel is:
$objPHPExcel->getActiveSheet()->setCellValue('G32', "=SUM(G31:INDIRECT(ADDRESS(ROW()-1;COLUMN())))");
Where am I wrong? Thanks.
The reference to the cell should be in the INDIRECT statement, not in SUM and mustn't contain space. That is
=SUM(INDIRECT("G31:"&ADDRESS(ROW()-1;COLUMN())))
on the output which is triggered by
$objPHPExcel->getActiveSheet()->setCellValue('G32', "=SUM(INDIRECT(\"G31:\"&ADDRESS(ROW()-1,COLUMN())))");
in PHPExcel.
This works.
I've been working with PHPExcel over the last few days and so far it's been perfect for what I need. However, today I've been trying to use mergeCells for "colspan" functionality but when I do it causes unreadable content errors and MS Excel prompts me to repair the file.
The code I'm using is:
$first = PHPExcel_Cell::stringFromColumnIndex($xCount).$yCount;
$second = PHPExcel_Cell::stringFromColumnIndex( $xCount + 2).$yCount;
$cell_merge = $first.":".$second;
$this->excelDoc->getActiveSheet()->mergeCells( $cell_merge );
I've output the result of $first, $second and $cell_merge to ensure I'm going about it the right way and the content is correct. Furthermore, when I try a static merge of cells (by entering mergeCells('A1:C1'); it works perfectly.
Would it be possible that trying to write to a merged cell would cause problems?
EDIT: just a note: I also tried to cast the variable as string just in case like this:
$this->excelDoc->getActiveSheet()->mergeCells( (string)$cell_merge );
... but no luck.
Just for future reference. The problem here existed between the keyboard and chair.
I was attempting to change the colspan during a loop and in this loop I had a call to mergeCells with 'A0:C0'.
When passing row "0" I wasn't getting any errors, just a bad excel sheet. Something to bear in mind.