PhpExcel加载动态模板

时间:2014-09-04 08:25:14

标签: php codeigniter phpexcel

我正在尝试加载一个动态的excel xlsx文件模板,我尝试使用以下方法:

$approve_employee_id = $this->input->post('approve_employee_id');
$query = "SELECT * from employee where employee.employee_id='$approve_employee_id'";
        $query = $this->db->query($query);
        foreach ($query->result() as $value) {
            $f_name = $value->f_name;
            $s_name = $value->s_name;
            $user_name = $value->user_name;
            $under_score = "_";
            $file_name = $user_name . $under_score . $approve_month_id . $under_score . $approve_year_name;
            $folder_name = $approve_month_id . $approve_year_name;

            $basedir = $_SERVER['DOCUMENT_ROOT'] . "/timesheet/files";
            $this->load->library('excel');


            $objPHPexcel = PHPExcel_IOFactory::load("/Applications/MAMP/htdocs/timesheet/files/un_approved/'$file_name'.xlsx");
            echo 'Loading template successfull...';
            $objWorksheet = $objPHPexcel->getActiveSheet();
}

如何以动态方式加载文件名? 以下是文件名之一:HS103_January_2014

1 个答案:

答案 0 :(得分:0)

查看您尝试加载的文件名:

"/Applications/MAMP/htdocs/timesheet/files/un_approved/'$file_name'.xlsx"

如果$file_name的值为HS103_January_2014,则会尝试加载

/Applications/MAMP/htdocs/timesheet/files/un_approved/'HS103_January_2014'.xlsx

实际文件名中是否真的有单引号?

使用

$objPHPexcel = PHPExcel_IOFactory::load(
    "/Applications/MAMP/htdocs/timesheet/files/un_approved/{$file_name}.xlsx"
);