I am using laravel. I want to read an excel file and add a new column to the left of the first column on each sheet using PHP. (The excel file can have as many as 10 sheets)
concatenate "AFS-" to the data in each row of the first column and store the new string in the new column to the left.
Code Below.
$finalFile = "";
/** Load $inputFileName to a PHPExcel Object **/
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$worksheet->insertNewColumnBefore('A', 1); //To insert a single new column before column A:
foreach($worksheet->getRowIterator() as $row)
{
$worksheet->setCellValue('A'.$row, 'AFS-' . $worksheet->getCell("B".$row)->getValue());
}
}
$convertedFileName = "converted-file". $date->getTimestamp().".xlsx";
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($directory . $convertedFileName);