How to download an excel template and write it in PHPExcel?

How to load an Excel template using PHPExcel and write it to cells, and also insert images into cells dynamically?

+8
php templates phpexcel
source share
2 answers

You can read your excel template like this with PHPExcel:

$objPHPExcel = PHPExcel_IOFactory::load("./forms/english/cash.xlsx"); 

and you can write to cells as follows:

  $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A2', "No") ->setCellValue('B2', "Name") ->setCellValue('C2', "Email") ->setCellValue('D2', "Phone") ->setCellValue('E2', "Address"); 
+15
source share

see example, 30template.php on github

https://github.com/PHPOffice/PHPExcel/blob/develop/Examples/30template.php

Download the template:

 $objReader = PHPExcel_IOFactory::createReader('Excel5'); $objPHPExcel = $objReader->load("templates/30template.xls"); 

see example write via

 $objPHPExcel->getActiveSheet()->setCellValue() 

add using PHPExcel_Worksheet_Drawing image:

 // Add an image to the worksheet $objDrawing = new PHPExcel_Worksheet_Drawing(); $objDrawing->setName('My Image'); $objDrawing->setDescription('The Image that I am inserting'); $objDrawing->setPath('./images/myImage.png'); $objDrawing->setCoordinates('B2'); $objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); 
+7
source share

All Articles