Closed entheologist closed 8 years ago
:) I'm glad you found what was wrong!
PS: why you iterate through a loop, you can jus creat an multi-demension array and use $writer->addRows($your_array);
notice addRows
with s
if you already get the data from your database you don't need to run a loop :)
It is highly recommended to avoid fetching data all at once, as it can lead to out of memory issues (because this data needs to be stored entirely in memory). Instead, data should be fetched by batch and you'll need a loop to write it using Spout. In this case, only the chunk of data fetched will live in memory.
But if you're 100% sure that the fetched data will fit in memory, then it may be easier to fetch everything and use Writer::addRows()
as you suggested @xmoroccan
i already fetch a database with almost 30,000 rows (i know that there are huge databases, compared to mine) and i export it as ods file with no problems, example:
$stmt = $link->prepare("SELECT columns, you, want FROM table");
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$writer = Box\Spout\Writer\WriterFactory::create(Box\Spout\Common\Type::ODS);
$writer->openToFile(__DIR__.'/../ods/'.$Target_File);
//Add header
$writer->addrow($headers);
$writer->addRows($results);
$writer->close();
return $Target_File;
EDIT: Ah I see the problem is that I was calling `$this->writer->openToFile($this->ods_file);`` multiple times, and it was deleting the data that was already in there. Thank you for creating this great tool.
I'm trying to add rows to the stylesheet by running a loop. Heres the code I use to initiate the file writer:
$this->writer = WriterFactory::create(Type::ODS); $this->writer->openToFile($this->ods_file);
and heres the code thats inside the loop:
$this->writer->addRow($data);
This is what the data array looks like:
But when I check the ODS file, theres only one row in there, its the last row that was inserted. Am I doing something wrong here?