1: <?php
2:
3: namespace SimpleExcel\Writer;
4:
5: /**
6: * SimpleExcel class for writing CSV Spreadsheet
7: *
8: * @author Faisalman
9: * @package SimpleExcel
10: */
11: class CSVWriter extends BaseWriter
12: {
13: /**
14: * Defines content-type for HTTP header
15: *
16: * @access protected
17: * @var string
18: */
19: protected $content_type = 'text/csv';
20:
21: /**
22: * Defines delimiter char
23: *
24: * @access protected
25: * @var string
26: */
27: protected $delimiter = ',';
28:
29: /**
30: * Defines file extension to be used when saving file
31: *
32: * @access protected
33: * @var string
34: */
35: protected $file_extension = 'csv';
36:
37: /**
38: * Get document content as string
39: *
40: * @param array $options Options
41: * @return string Content of document
42: */
43: public function toString ($options = NULL) {
44: if (isset($options['delimiter'])) {
45: $this->delimiter = $options['delimiter'];
46: }
47: $fp = fopen('php://temp', 'r+');
48: foreach ($this->workbook->getWorksheets() as $worksheet) {
49: foreach ($worksheet->getRecords() as $record) {
50: $row = array();
51: foreach ($record as $cell) {
52: array_push($row, $cell->value);
53: }
54: fputcsv($fp, $row, $this->delimiter);
55: }
56: }
57: rewind($fp);
58: $content = stream_get_contents($fp);
59: fclose($fp);
60: return $content;
61: }
62: }
63: ?>
64: