发布时间:2019-10-26 13:34:51 作者:佚名 阅读:(260)
最近在使用PHPExcel生成报表文档,单个sheet的时候没有问题,在生成多个sheet的时候就报错了:You tried to set a sheet active by the out of bounds index: 1. The actual number of sheets is 1接下来吾爱编程为您介绍一下解决方法:
PHPExcel是一款非常强大的PHP操作EXCEL库,使用PHPExcel可以帮助我们简单、高效实现从Excel读取Excel的数据和导出数据到Excel。
最近在使用PHPExcel生成多个sheet时,会提示You tried to set a sheet active by the out of bounds index: 1. The actual number of sheets is 1错误,因为我是生成两个,所以在代码直接写了两个sheet,代码如下:
$objPHPExcel = new PHPExcel(); // Set document properties $objPHPExcel->getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("Test result file"); // Add some data $objPHPExcel->createSheet(); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', '名称') ->setCellValue('B1', '资源') ->setCellValue('C1', '总量'); $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10); $x = 2; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A'.$x, '测试') ->setCellValue('B'.$x, '测试') ->setCellValue('C'.$x, '测试'); $objPHPExcel->getActiveSheet()->setTitle('Resource'); $objPHPExcel->setActiveSheetIndex(0);
重要的一句:$objPHPExcel->createSheet();如果你要循环生成很多个的话,可以把这一句放在循环的里面
欢迎分享转载→ PHPExcel生成多sheet报错You tried to set a sheet active by the out of bounds index: 1. The actual number of sheets is 1
Vue框架如何与PHP打造前后端分离的管理系统
(0)人喜欢 2023-03-03Deprecated: Methods with the same name as their class will not be constructors
(2975)人喜欢 2022-09-01if condition多个值_thinkphp if标签的condition用法
(3458)人喜欢 2022-08-31PHP获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法
(64)人喜欢 2019-06-11PHP判断是否是序列化字符串数据的函数
(1469)人喜欢 2015-11-21php数组排序详解
(40)人喜欢 2015-11-21© 2015-2021 - 吾爱编程网 版权所有 苏ICP备18033726号-1关于我们 - 网站声明 - 联系我们