I am writing some code to open an excel file then creating a new column and appending the data from column 2 to column 1. However the file is not saving.
I am loading this data in my local Wamp. The project is in Laravel
// create new file with results $date = new \DateTime();
// create new file with results
$date = new \DateTime();
$directory = base_path() . '/storage/tmp/';
/** 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);