我正在使用 php excel 将数据和图像徽标写入 excel 文件,目前它可以工作,数据按指定写入表 2,但徽标写入表 0,如果我在 getActiveSheet() 中传递一个值说 2,对于图像与数据相同,没有任何反应,我的 excel 文件似乎消失了,我做错了什么?
public function getDataToExcel() {
$labref = $this->uri->segment(3);
$SampleName = $this->input->post('SampleName');
$LabRef = $this->input->post('LabRef');
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("workbooks/" . $labref . "/" . $labref . ".xlsx");
$objPHPExcel->getActiveSheet(2);
$objWorkSheet = $objPHPExcel->createSheet();
$objWorkSheet->setCellValue('B40', $SampleName)
->setCellValue('B41', $LabRef);
$objWorkSheet->setTitle("Sample Summary");
$dir = "workbooks";
if (is_dir($dir)) {
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('NQCL');
$objDrawing->setDescription('The Image that I am inserting');
$objDrawing->setPath('exclusive_image/nqcl.png');
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save("workbooks/" . $labref . "/" . $labref . ".xlsx");
echo 'Data exported';
} else {
echo 'An error occured';
}
}