PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.2k forks source link

Looping through First Row #1294

Closed socialpixe closed 6 years ago

socialpixe commented 6 years ago

Hello there,

I am really FEDUP with this library, if i am looking for basic PHP Excel writter i always get this and nothing happens and won't solve my problem.

So finally i am writting, can anybody please tell me is there anyway to loop through Top Row of excel.

I need something like this loop

socialpixe commented 6 years ago

WORST LIBRARY ... SEEMS LIKE IT IS DEVELOPED FOR READING NOT WRITTING

PowerKiKi commented 6 years ago

Your frustration for not being able to code a loop is certainly not a good indicator of the quality of this library.

<?php

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

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
foreach (range(1, 10) as $i) {
    $sheet->setCellValueByColumnAndRow($i, 1, $i);
}

$writer = new Xlsx($spreadsheet);
$filename = '/tmp/test.xlsx';
$writer->save($filename);
echo 'saved to: ' . $filename . PHP_EOL;