我有excel 2007文档,有10张,但是当我尝试用PHPExcel编辑它时,这些工作表的所有内容(第一个和PHPExcel输入除外)都被删除了。
这是我的代码:
require 'PHPExcel.php';
require 'PHPExcel/IOFactory.php';
require 'PHPExcel/Writer/Excel2007.php';
$fileType = 'Excel2007';
$fileName = 'test.xlsx';
$objReader = PHPExcel_IOFactory::createReader($fileType);
$objPHPExcel = $objReader->load($fileName);
$activeSheet = $objPHPExcel->setActiveSheetIndexbyName('ID');
$activeSheet->setCellValue('A2', 'string test');
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($fileName);
答案 0 :(得分:0)
通过查看此post尝试重新排列代码,如下所示:
require 'PHPExcel.php';
require 'PHPExcel/IOFactory.php';
require 'PHPExcel/Writer/Excel2007.php';
$fileType = 'Excel2007';
$fileName = 'test.xlsx';
$objPHPExcel = PHPExcel_IOFactory::createReader($fileType);
$objPHPExcel = $objPHPExcel->load($fileName);
$objPHPExcel->setActiveSheetIndexbyName('ID');
$objPHPExcel->getActiveSheet()->setCellValue('A2', 'string test');
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($fileName);