Skip to content

Commit a203c27

Browse files
Merge pull request SpartnerNL#449 from maddhatter/string-export
Ability to export as a string
2 parents 0ade0c2 + cb60896 commit a203c27

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/Maatwebsite/Excel/Writers/LaravelExcelWriter.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,32 @@ public function download($ext = 'xls', Array $headers = array())
283283
$this->export($ext, $headers);
284284
}
285285

286+
/**
287+
* Return the spreadsheet file as a string
288+
* @param string $ext
289+
* @return string
290+
* @throws LaravelExcelException
291+
*/
292+
public function string($ext = 'xls')
293+
{
294+
// Set the extension
295+
$this->ext = $ext;
296+
297+
// Render the file
298+
$this->_render();
299+
300+
// Check if writer isset
301+
if (!$this->writer)
302+
throw new LaravelExcelException('[ERROR] No writer was set.');
303+
304+
//Capture the content as a string and return it
305+
ob_start();
306+
307+
$this->writer->save('php://output');
308+
309+
return ob_get_clean();
310+
}
311+
286312
/**
287313
* Download a file
288314
* @param array $headers

0 commit comments

Comments
 (0)