getActiveSheet()->setCellValue('A1', 'foo'); $writer = IOFactory::createWriter($spreadsheet, $format); $stream = fopen('php://memory', 'wb+'); self::assertSame(0, fstat($stream)['size']); $writer->save($stream); self::assertIsResource($stream, 'should not close the stream for further usage out of PhpSpreadsheet'); self::assertGreaterThan(0, fstat($stream)['size'], 'something should have been written to the stream'); self::assertGreaterThan(0, ftell($stream), 'should not be rewinded, because not all streams support it'); } }