Allow setting of header content type for CSVs.

This commit is contained in:
Aron Budinszky 2017-06-26 17:21:21 +02:00
parent 40b4a57e6b
commit 9bd56fce52
4 changed files with 17 additions and 5 deletions

View File

@ -37,7 +37,7 @@ abstract class AbstractWriter implements WriterInterface
protected $defaultRowStyle;
/** @var string Content-Type value for the header - to be defined by child class */
protected static $headerContentType;
protected $headerContentType;
/**
* Opens the streamer and makes it ready to accept data.
@ -143,7 +143,7 @@ abstract class AbstractWriter implements WriterInterface
$this->globalFunctionsHelper->ob_end_clean();
// Set headers
$this->globalFunctionsHelper->header('Content-Type: ' . static::$headerContentType);
$this->globalFunctionsHelper->header('Content-Type: ' . $this->headerContentType);
$this->globalFunctionsHelper->header('Content-Disposition: attachment; filename="' . $this->outputFilePath . '"');
/*

View File

@ -18,7 +18,7 @@ class Writer extends AbstractWriter
const FLUSH_THRESHOLD = 500;
/** @var string Content-Type value for the header */
protected static $headerContentType = 'text/csv; charset=UTF-8';
protected $headerContentType = 'text/csv; charset=UTF-8';
/** @var string Defines the character used to delimit fields (one character only) */
protected $fieldDelimiter = ',';
@ -58,6 +58,18 @@ class Writer extends AbstractWriter
return $this;
}
/**
* Set the header content type.
*
* @param string $headerContentType Content-Type value for the header if different than default UTF-8.
* @return Writer
*/
public function setHeaderContentType($headerContentType)
{
$this->headerContentType = $headerContentType;
return $this;
}
/**
* Set if a BOM has to be added to the file
*

View File

@ -15,7 +15,7 @@ use Box\Spout\Writer\ODS\Internal\Workbook;
class Writer extends AbstractMultiSheetsWriter
{
/** @var string Content-Type value for the header */
protected static $headerContentType = 'application/vnd.oasis.opendocument.spreadsheet';
protected $headerContentType = 'application/vnd.oasis.opendocument.spreadsheet';
/** @var string Temporary folder where the files to create the ODS will be stored */
protected $tempFolder;

View File

@ -19,7 +19,7 @@ class Writer extends AbstractMultiSheetsWriter
const DEFAULT_FONT_NAME = 'Calibri';
/** @var string Content-Type value for the header */
protected static $headerContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
protected $headerContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
/** @var string Temporary folder where the files to create the XLSX will be stored */
protected $tempFolder;