Add resource parameter handling to html, csv and xls writers
This commit is contained in:
parent
ccb49de301
commit
11499aad9a
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer;
|
|||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException;
|
||||
|
||||
class Csv extends BaseWriter
|
||||
{
|
||||
|
@ -77,7 +78,7 @@ class Csv extends BaseWriter
|
|||
/**
|
||||
* Save PhpSpreadsheet to file.
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param resource|string $pFilename
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -92,9 +93,14 @@ class Csv extends BaseWriter
|
|||
Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE);
|
||||
|
||||
// Open file
|
||||
$fileHandle = fopen($pFilename, 'wb+');
|
||||
if (is_resource($pFilename)) {
|
||||
$fileHandle = $pFilename;
|
||||
} else {
|
||||
$fileHandle = fopen($pFilename, 'wb+');
|
||||
}
|
||||
|
||||
if ($fileHandle === false) {
|
||||
throw new Exception("Could not open file $pFilename for writing.");
|
||||
throw new WriterException("Could not open file $pFilename for writing.");
|
||||
}
|
||||
|
||||
if ($this->excelCompatibility) {
|
||||
|
@ -126,6 +132,8 @@ class Csv extends BaseWriter
|
|||
}
|
||||
|
||||
// Close file
|
||||
rewind($fileHandle);
|
||||
|
||||
fclose($fileHandle);
|
||||
|
||||
Calculation::setArrayReturnType($saveArrayReturnType);
|
||||
|
|
|
@ -146,7 +146,7 @@ class Html extends BaseWriter
|
|||
/**
|
||||
* Save Spreadsheet to file.
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param resource|string $pFilename
|
||||
*
|
||||
* @throws WriterException
|
||||
*/
|
||||
|
@ -164,7 +164,12 @@ class Html extends BaseWriter
|
|||
$this->buildCSS(!$this->useInlineCss);
|
||||
|
||||
// Open file
|
||||
$fileHandle = fopen($pFilename, 'wb+');
|
||||
if (is_resource($pFilename)) {
|
||||
$fileHandle = $pFilename;
|
||||
} else {
|
||||
$fileHandle = fopen($pFilename, 'wb+');
|
||||
}
|
||||
|
||||
if ($fileHandle === false) {
|
||||
throw new WriterException("Could not open file $pFilename for writing.");
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ class Xls extends BaseWriter
|
|||
/**
|
||||
* Save Spreadsheet to file.
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param resource|string $pFilename
|
||||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue