【问题标题】:phpword library proplem with foreach?foreach 的 phpword 库问题?
【发布时间】:2014-07-19 20:58:17
【问题描述】:

您好,当我想循环我的信息时,我遇到了 phpword 库的问题

    // Education Foreach
$get_education = $this->db->query("SELECT * FROM `member_edu` WHERE Memberid='".$user_id."'");
foreach ($get_education->result() as $edu_row){
    $edu_json    = json_decode($edu_row->edu_details);
    $college     = $edu_json->College_name;
    $University  = $edu_json->University_name;
    $Degree      = $edu_json->Degree_name;
    $Grade       = $edu_json->Grade;
    $Special     = $edu_json->Speciality;
    $EduFrom     = $edu_json->From;
    $EduTo       = $edu_json->To;
    //// Values for loop in .docx file
    $document->cloneRow('rowEdu', $get_education->num_rows());
    $document->setValue('rowEdu#1', $college);
    $document->setValue('rowUniversity#1', $University);
    $document->setValue('rowDegree#1', $Degree);
    $document->setValue('rowGrade#1', $Grade);
    $document->setValue('rowSpeciality#1', $Special);
    $document->setValue('rowEdufrom#1', $EduFrom);
    $document->setValue('rowEduto#1', $EduTo);
}

这是我的代码,当member_edu 有一个记录时一切正常,当我添加新教育时,循环出现错误。

错误代码:

Fatal error: Uncaught exception 'PhpOffice\PhpWord\Exception\Exception' with message 

'Can not clone row, template variable not found or variable contains markup.' in C:\xampp\htdocs\icareer\application\third_party\phpword\Template.php:186 Stack trace:
#0 C:\xampp\htdocs\icareer\application\views\resume\preview_view.php(59): PhpOffice\PhpWord\Template->cloneRow('rowEdu', 2)
#1 C:\xampp\htdocs\icareer\system\core\Loader.php(833): include('C:\xampp\htdocs...')
#2 C:\xampp\htdocs\icareer\system\core\Loader.php(419): CI_Loader->_ci_load(Array)
#3 C:\xampp\htdocs\icareer\application\controllers\ci_resume.php(722): CI_Loader->view('resume/preview_...', Array)
#4 [internal function]: CI_Resume->preview()
#5 C:\xampp\htdocs\icareer\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array)
#6 C:\xampp\htdocs\icareer\index.php(202): require_once('C:\xampp\htdocs...') #7 {main} thrown in C:\xampp\htdocs\icareer\application\third_party\phpword\Template.php on line 186

我不知道我能做什么这是第一次在 PHP 单词库中工作有人可以帮助我吗?

【问题讨论】:

    标签: php codeigniter for-loop foreach phpword


    【解决方案1】:

    您好,我自己找到了解决问题的方法,谢谢您的帮助:)

    还有这个正确的代码。

      // Education Foreach
      $get_education = $this->db->query("SELECT * FROM `member_edu` WHERE Memberid='".$user_id."' ORDER BY `member_edu`.`edu_id` DESC");
      $document->cloneRow('rowEdu', $get_education->num_rows());
      $i=1;
      foreach ($get_education->result() as $edu_row){
          $edu_json    = json_decode($edu_row->edu_details);
          // Values for loop in .docx file
          $document->setValue('rowEdu#'.$i, $edu_json->College_name);
          $document->setValue('rowUniversity#'.$i, $edu_json->University_name);
          $document->setValue('rowDegree#'.$i, $edu_json->Degree_name);
          $document->setValue('rowGrade#'.$i, $edu_json->Grade);
          $document->setValue('rowSpeciality#'.$i, $edu_json->Speciality);
          foreach ($countries as $key => $country) {
            if ($key == $edu_json->Cuntry){
              $document->setValue('rowCountry#'.$i,$country);
            }
          }
          $document->setValue('rowEdufrom#'.$i, $edu_json->From);
          $document->setValue('rowEduto#'.$i, $edu_json->To);
          $i++;
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 2021-11-02
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多