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.
Related
Is it possible to start printing on a particular label (set by a $_POST) value? If I have 10 labels to a page, and I want them to start on the 3rd label (2nd label on the 2nd row), is there a way to tell either FPDF or TCPDF to do that?
Update:
This is where the class for fPDF labels comes from:
fPDF Label Class
The line of code that controls this in fPDF is:
function __construct($format, $unit='mm', $posX=1, $posY=1)
When I change the $posx=__ and the $posY=__, the labels DO start printing in different positions!
However, when I set:
function __construct($format, $unit='mm', $posX=$setthex, $posY=$setthey)
I get an error: PHP Fatal error: Constant expression contains invalid operations
I've read about this on SO, but I'm at a loss regarding 'Static' issues...
I figured it out, kind of .. Not with these variables, but by inserting X amount of blank labels before I started printing the correct ones.
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.)
It seems that PHPExcel TYPE_LIST has a limited length.
$formula = $objPHPExcel->getActiveSheet()->getCell('A2')->getDataValidation();
$formula->setType(PHPExcel_Cell_DataValidation::TYPE_LIST);
$formula->setErrorStyle(PHPExcel_Cell_DataValidation::STYLE_INFORMATION);
$formula->setFormula1($countriesList);
The following string works in the dropdown list:
Afghanistan,Albania,Algeria,American
Samoa,Andorra,Angola,Anguilla,Antarctica,Antigua and
Barbuda,Argentina,Armenia,Aruba,Australia,Austria,Azerbaijan,Bahamas,Bahrain,Bangladesh,Barbados,Belarus,Belgium,Belize,Benin,Bermuda,Bhutan,Bolivia,Bosnia
and Herze
Althought you may have notice that the last word "Herze" is not correct. The correct word is "Herezegovina". If I try to send all the text into the dropdown it stops working.
Afghanistan,Albania,Algeria,American
Samoa,Andorra,Angola,Anguilla,Antarctica,Antigua and
Barbuda,Argentina,Armenia,Aruba,Australia,Austria,Azerbaijan,Bahamas,Bahrain,Bangladesh,Barbados,Belarus,Belgium,Belize,Benin,Bermuda,Bhutan,Bolivia,Bosnia
and Herzegovina
It seems that the maximum length is 255 and I would like someone to confirm me this? and if there's other option to show all the items as dropdown?
You can use a LOOKUP formula instead of a list
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.
I'm making some pdf document from php code using fpdf library. In that document i have created two cell like this
$pdf->Cell(100,100,"Text inside first column",1,0,'L');
$pdf->Cell(35,35,'Text inside second column ',1,0,'C');
above code works well, out put have two cells, first one has size of 100x100 and second has 35x35 , and second cell was just right to the first cell.
but i need to print that second sell inside the first cell
is there any way in fpdf ?
can anyone help me?
I'm not sure what you want exactly achive, but maybe this AddOn could help you to do this:
http://www.interpid.eu/fpdf-table
Other way would be moving the pointer, something like this:
$pdf->Cell(100,100,"Text inside first column",1,0,'L');
$pdf->SetX($pdf->GetX() - 35);
$pdf->Cell(35,35,'Text inside second column ',1,0,'C');
In Nested cell X-axis and Y-axis, I have achieved like this
`$pdf->Cell(190,20,"",1,0,'L');
$pdf->SetX($pdf->GetX() - 189);
$pdf->Cell(100,10,'First ',2,0,'L');
$pdf->Cell(90,10,'March/2020 ',2,0,'R');
$pdf->SetY($pdf->GetY() +5);
$pdf->Cell(100,10,'MCB,UBl Omni, HBL Konnect, Alfalah , Mobi Cash ',2,0,'L');
$pdf->SetY($pdf->GetY() +5);`enter code here`
$pdf->Cell(139,10,'third text he`enter code here`re ',2,0,'L');
$pdf->Cell(50,10,'Lahore',2,0,'R');`