Phpexcel is very powerful, but I've been looking for a long day, and I can't find the alternative input function. For example, I entered {name} in any of the Excel templates and entered {age}. How do I replace {name} with Cheng Changsan and replace {age} with 20 function? Replace it and save it for download by the user.
(The example I see now is to locate d1,a2 similar to this.) Not this one.)
Please understand the friend must teach me, thank you.
Reply to discussion (solution)
Each cell in EXCEL is independent, so this is true in Phpexcel.
For the sake of memory reduction, Phpexcel does not read the worksheet into memory at once, so locating cells by row and column is unavoidable.
For your application that fills in the template
You simply traverse the active area of the worksheet and replace each template element.
I also met a similar. http://bbs.csdn.net/topics/390548827
In fact, these are conditional formatting of cells,
There are examples on the Internet, but the exact same is not easy to write in my code.
And wait for the great Gods ' guidance.
Include ' plugin/phpexcel/classes/phpexcel/iofactory.php '; class Fill_template {var $startrow = 0; function __construct ($FN) {$this->tpl = phpexcel_iofactory::load ($FN); $this->target = Clone $this->tpl; } function Add_data ($ar) {$sheet = $this->tpl->getactivesheet (); $i = 0; $mcol = $sheet->gethighestcolumn (); foreach ($sheet->getrowdimensions () as $y = + $row) {for ($x = ' A '; $x <= $mcol; $x + +) {$txt = Trim ($sheet-& Gt;getcell ($x. $y)->getvalue ()); if ($txt && preg_match ('/{(. +)}/', $txt, $match)) {$txt = Isset ($ar [$match [1]])? iconv (' GBK ', ' Utf-8 ', $ ar[$match [1]]): "; } $h = $y + $this->startrow; $this->target->getactivesheet ()->getcell ("$x $h")->setvalue ($txt); $this->target->getactivesheet ()->duplicatestyle ($sheet->getstyle ("$x $y"), "$x $h"); }} foreach ($sheet->getmergecells () as $merge) {$merge = preg_replace ('/\d+/e ', "$0+ $thIs->startrow ", $merge); $this->target->getactivesheet ()->mergecells ($merge); }} function output ($FN) {$t = Phpexcel_iofactory::createwriter ($this->target, ' Excel5 '); $t->save ($FN); }} $p = new Fill_template (' Tpl02.xls '), $p->add_data (' name ' = ' Zhang San ', ' age '); $p->output (' Xxx02.xls ');
Thank you, xuzuning. CSDN is powerful.