'XLSXWriter write arrays variables to excel
How can i write variables from arrays to excel. The array is looking like this:
Array
(
[0] => 0
[1] => color
)
Array
(
[0] => 0
[1] => 3
[2] => 4
)
Array
(
[0] => color
[1] => size
)
XLSXWriter is only writing the last array to the file.
$header = [ '1' => 'string',
'2' => 'string',
'3' => 'string',
'4' => 'string' ];
$writer = new XLSXWriter();
$writer->setAuthor('AUTHOR');
$writer->writeSheet($exceldata, 'SHEET1', $header);
$writer->writeToFile("/mnt/excel/" . "file.xlsx" );
Solution 1:[1]
Use array with data and write it in your file.
$header = [ '1' => 'string',
'2' => 'string',
'3' => 'string',
'4' => 'string' ];
// This is array with data
// $data = file_get_contents($url);
$data = array(
array('0','color'),
array('0','3','4'),
array('color', 'size')
);
$writer = new XLSXWriter();
$writer->writeSheetHeader('Sheet1', $header );
// Let's write the data
foreach($data as $row) {
$writer->writeSheetRow('Sheet1', $row );
}
$writer->writeToFile("/mnt/excel/" . "file.xlsx");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sergei |
