0

Following is the code in which I am using the PhpSpreadsheet library to convert xlsx file to csv. I am trying to achieve the ability that the converted file should have one extra column called ClientID which should contain the same value for all the number of rows present in that file. Please let me know is it possible to do? Any help would be highly appreciated.

use \PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use \PhpOffice\PhpSpreadsheet\Writer\Csv;

$reader = new Xlsx();
        $uploaded_xls_file = $_FILES['file']['tmp_name'];
        $spreadsheet = $reader->load($uploaded_xls_file); 

        $loadedSheetNames = $spreadsheet->getSheetNames();

        $writer = new Csv($spreadsheet);

        foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
            $writer->setSheetIndex($sheetIndex);
            $writer->setPreCalculateFormulas(false);
            $savingpath = $loadedSheetName.'.csv';
            $writer->save($savingpath);
            //$writer->save($loadedSheetName.'.csv');
        }
Rand
  • 27
  • 8
  • [Duplicate](https://stackoverflow.com/a/34952158) – idfurw Sep 02 '21 at 00:34
  • Does this answer your question? [How can I create a new column and concatenate some values using php Excel?](https://stackoverflow.com/questions/34951969/how-can-i-create-a-new-column-and-concatenate-some-values-using-php-excel) – idfurw Sep 02 '21 at 02:52

0 Answers0