Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  
   3  namespace Box\Spout\Writer;
   4  
   5  use Box\Spout\Common\Entity\Row;
   6  use Box\Spout\Common\Entity\Style\Style;
   7  
   8  /**
   9   * Interface WriterInterface
  10   */
  11  interface WriterInterface
  12  {
  13      /**
  14       * Initializes the writer and opens it to accept data.
  15       * By using this method, the data will be written to a file.
  16       *
  17       * @param  string $outputFilePath Path of the output file that will contain the data
  18       * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable
  19       * @return WriterInterface
  20       */
  21      public function openToFile($outputFilePath);
  22  
  23      /**
  24       * Initializes the writer and opens it to accept data.
  25       * By using this method, the data will be outputted directly to the browser.
  26       *
  27       * @param  string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept
  28       * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
  29       * @return WriterInterface
  30       */
  31      public function openToBrowser($outputFileName);
  32  
  33      /**
  34       * Sets the default styles for all rows added with "addRow".
  35       * Overriding the default style instead of using "addRowWithStyle" improves performance by 20%.
  36       * @see https://github.com/box/spout/issues/272
  37       *
  38       * @param Style $defaultStyle
  39       * @return WriterInterface
  40       */
  41      public function setDefaultRowStyle(Style $defaultStyle);
  42  
  43      /**
  44       * Appends a row to the end of the stream.
  45       *
  46       * @param Row $row The row to be appended to the stream
  47       * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yet
  48       * @throws \Box\Spout\Common\Exception\IOException If unable to write data
  49       * @return WriterInterface
  50       */
  51      public function addRow(Row $row);
  52  
  53      /**
  54       * Appends the rows to the end of the stream.
  55       *
  56       * @param Row[] $rows The rows to be appended to the stream
  57       * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
  58       * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yet
  59       * @throws \Box\Spout\Common\Exception\IOException If unable to write data
  60       * @return WriterInterface
  61       */
  62      public function addRows(array $rows);
  63  
  64      /**
  65       * Closes the writer. This will close the streamer as well, preventing new data
  66       * to be written to the file.
  67       *
  68       * @return void
  69       */
  70      public function close();
  71  }