我正在使用php excel将数据和图像徽标写入excel文件,目前它的工作原理,数据按照指定的方式写在表2中,但是如果我在getActiveSheet中传递值2,则表示徽标写在表0中( ),对于与数据相同的图像,没有任何反应,我的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';
}
}
答案 0 :(得分:1)
您的问题是理解getActiveSheet()
方法
$objPHPExcel->getActiveSheet(2);
getActiveSheet()
不接受任何参数,只返回当前活动的工作表;所以2是没有意义的。
要设置当前活动工作表,您需要调用
$objPHPExcel->setActiveSheet(2);