Detailed explanation of PHPExcel modification steps

php中世界最好的语言
Release: 2023-03-25 21:12:01
Original
1583 people have browsed it

This time I will bring you a detailed explanation of the steps to modify PHPExcel. What are the precautions for modifying PHPExcel? The following is a practical case, let’s take a look.

is as follows:

require_once './Classes/PHPExcel/IOFactory.php';
  $filePath = './Template.xlsx';
  //读取文件
  if (!file_exists($filePath)) {
     exit("you dont have ");
  }
  $objPHPExcel = PHPExcel_IOFactory::load($filePath);
  $sheet = $objPHPExcel->getSheet(0); // 读取第一個工作表
  $highestColumm = $sheet->getHighestColumn(); // 取得总列数
  $highestRow = $sheet->getHighestRow(); // 取得总行数
  /** 循环读取每个单元格的数据 */
  $i = 2;
  foreach ($list as $key => $value) {
      $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('Z'.$i, $value['demo'])
            ->setCellValue('AA'.$i, $value['demo']);
      $i++;
  }
  $objPHPExcel->getActiveSheet()->setTitle('Simple');
  $objPHPExcel->setActiveSheetIndex(0);
  /** 输出到指定目录 */
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  $objWriter->save('simple.xlsx');//文件保存路径
  /** 输出到浏览器直接下载打开 */
  $file_name = 'batchTemplate.xlsx';
  header('Content-Type:application/vnd.ms-excel'); //指定下载文件类型
  header('Content-Disposition: attachment; filename="'.$file_name.'"'); //指定下载文件的描述
  header('Content-Length:'.filesize($input_file)); //指定下载文件的大小
  /** 将文件内容读取出来并直接输出,以便下载 */
  readfile($input_file);
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the php Chinese website article!

Recommended reading:

Detailed explanation of PHP ajax implementation of obtaining news data case

PHP calculates the integer set of extra large numbers

The above is the detailed content of Detailed explanation of PHPExcel modification steps. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!