0

I'm trying to write data to an excel sheet using Box/Spout, using a writer I pass an array to the addrow() function, but when the excel file is done it is missing columns of data on the sheet...

The array has exactly the data I need and I var_dump() it to show the data. The data is originally coming from a mysql query, so I thought that adding the row directly from the mysqli_fetch_assoc function would work. After encountering this problem I created a variable row called $newRow and declared it as an array with the mysql fetch data inside. This still didn't work. Code below to explain my confusion...

Here is the var_dump of the row I am adding:

var_dump($newRow);
array(29) { 
[0]=> string(14) "X" 
[1]=> string(6) "X" 
[2]=> string(4) "X" 
[3]=> string(9) "X" 
[4]=> string(2) "X" 
[5]=> string(1) "X" 
[6]=> string(1) "X" 
[7]=> string(8) "X" 
[8]=> string(0) "" 
[9]=> string(8) "X" 
[10]=> string(16) "X" 
[11]=> string(16) "X" 
[12]=> string(0) "X" 
[14]=> string(7) "X" 
[15]=> string(2) "X" 
[16]=> string(2) "X" 
[17]=> string(1) "X" 
[18]=> string(2) "X" 
[19]=> string(2) "X" 
[20]=> string(2) "X" 
[21]=> string(15) "X" 
[22]=> string(9) "X" 
[23]=> string(2) "X" 
[24]=> string(5) "X" 
[25]=> string(16) "Y" 
[26]=> string(9) "Y" 
[27]=> string(2) "Y" 
[28]=> string(5) "Y" 
}

For privacy reasons I needed to replace the true data with X and Y. Please understand in doing so I replaced data that was truly there with these letters. I would include the mysql query that I used but it is unnecessary as it clearly pulls information successfully...

The next line is:

$writer->addrow($newRow);

Please bare in mind that the code looks exactly like this:

var_dump($newRow);
echo "<br/><br/>";
$writer->addrow($newRow);

And there is no change of $newRow before the $writer->addrow function.

Unfortunately, the excel sheet saves as

|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|

in a single row versus what is should be:

|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|Y|Y|Y|Y|

I have been boggling over this for hours and haven't found a solution. I hope my issue makes sense and any suggestions are greatly appreciated.

Pixelknight1398
  • 537
  • 2
  • 10
  • 33
  • Are you using `$writer->openToFile` or `$writer->openToBrowser`? – Adrien Jul 31 '19 at 07:14
  • Yes I use that at the beginning of my script to obviously initialize `$writer`. One thing I forgot to add into the question was that all of this goes into a function which I used `global $writer` in to get the same variable. Strangely about 20 hours ago it just started working out of nowhere. I didn't change any code at all and it started working. Will update here if anything happens. – Pixelknight1398 Aug 01 '19 at 00:48

1 Answers1

1

Try this

$writer->addRow(WriterEntityFactory::createRowFromArray($newRow));
Najmus Sakib
  • 737
  • 8
  • 12