Question: I have the following list :

```
theList= ["ABCD","EFGH","IJKL","MNOP"]

```

I want to write this list to a CSV file as different elements in each column in a single row. The final CSV file should look like;

```
  -----------------------------
1 | ABCD | EFGH | IJKL | MNOP |
  -----------------------------

```

I tried the following code (with csv library), but it writes to multiple rows instead of columns

```
tempRows = zip(theList)
    with open("Final.csv", 'w', newline='', encoding="utf8") as f:
        writer = csv.writer(f, delimiter=',')
        for tempRow in tempRows:
            writer.writerow(tempRow)

```

Answer: 
The problem with `addExternalSheet` was that I needed to name both sheets (the original that I load and the cloned Sheet) with the same name. (All files are here : <https://drive.google.com/open?id=1qkI8jdYDuA6e5CW6z3k0r_7j1pTvW_6D>, mergeSolved is the correct file) This is the code with the solution:

```
require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$inputFileType = 'Xlsx';
$inputFileNames = [
    'a.xlsx',
    'b.xlsx',
    'c.xlsx'
];
$sheetnames = [
    'Worksheet',
    'Worksheet1',
    'Worksheet2'
];
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$reader->setLoadSheetsOnly($sheetnames);
$inputFileName = array_shift($inputFileNames);
$spreadsheetMain = $reader->load($inputFileName);
$spreadsheetMain->getActiveSheet()->setTitle('page0');
$contador = 1;
foreach ($inputFileNames as $book => $inputFileName) {
    echo ('$inputFileName: ' . $inputFileName) . '</br>';
    $spreadsheet = $reader->load($inputFileName);
    $clonedWorksheet = clone $spreadsheet->getSheetByName('Worksheet'.$contador);
    $clonedWorksheet->setTitle('Worksheet'.$contador);
    $spreadsheetMain->addExternalSheet($clonedWorksheet);
    $contador++;
}
$writer = new Xlsx($spreadsheetMain);
$writer->save('prueba1.xlsx');`

```
```php
require 'vendor/autoload.php';

$lists = [
    'flie_01.xlsx',
    'flie_02.xlsx'
];

$outfile='/tmp/merge.xlsx';

$merge_spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();        
$merge_spreadsheet->getProperties()->setCreator("act");

foreach($lists as $file){

```
if(!file_exists($file)){
    continue;
}            

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
$reader-&gt;setReadDataOnly(true);
$spreadsheet = $reader-&gt;load($file);

foreach($spreadsheet-&gt;getSheetNames() as $sheet_name ){
    $clonedWorksheet = clone $spreadsheet-&gt;getSheetByName($sheet_name);
    $clonedWorksheet-&gt;setTitle($sheet_name);
    $merge_spreadsheet-&gt;addSheet($clonedWorksheet);                
}

```

}

$merge_spreadsheet->removeSheetByIndex(0);  

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet,'Xlsx');
$writer->save($outfile);

```