About Phpexcel help, understand the hero help AH

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.