PHPExcel method to modify existing Excel

不言
Release: 2023-03-25 09:16:02
Original
2063 people have browsed it

This article mainly introduces the method of modifying existing Excel with PHPExcel. It has certain reference value. Now I share it with you. Friends in need can refer to it

as follows Display:

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

Related recommendations:

How to import PHPExcel files into Thinkphp3.2.3

The above is the detailed content of PHPExcel method to modify existing Excel. 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!