我正在编写一些代码来打开excel文件,然后创建一个新列并将第2列的数据附加到第1列。但是文件没有保存。
我正在本地Wamp中加载这些数据。该项目位于Laravel
//创建包含结果的新文件 $ 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);