Coder Social home page Coder Social logo

nettecsvresponse's People

Contributors

vladahejda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

ohweb oaki

nettecsvresponse's Issues

Line ending

Zdravím
Šlo by doplnit do možností nastavení pro export ještě způsob ukončení řádků?
Prostě windows :-)
Přikládám supersimple řešení co jsem si udělal v extended třídě.

<?php
namespace App\Utils\Responses;

use Nette;

class CsvResponseWithLineEndingsSetting extends \OHWeb\Application\Responses\CsvResponse {

  /** line endings */
  const LF = "\n",
    CRLF = "\r\n";

  /** @var string */
  protected $line_endings = self::CRLF;


  /**
   * Line endings
   * @param string $line_endings
   * @return self
   * @throws \InvalidArgumentException
   */
   public function setLineEndings($line_endings) {
     if (empty($line_endings) || ($line_endings != self::LF && $line_endings != self::CRLF)) {
       throw new \InvalidArgumentException(__CLASS__.": line endings cannot be an empty and must be self::LF or self::CRLF.");
     }
     $this->line_endings = $line_endings;
     return $this;
   }


  /**
   * Sends response to output.
   * @param  NetteHttpIRequest  $httpRequest
   * @param  NetteHttpIResponse $httpResponse
   */
  public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse) {

    $httpResponse->setContentType($this->contentType, $this->outputCharset);

    $attachment = 'attachment';
    if (!empty($this->filename)) {
      $attachment .= '; filename="' . $this->filename . '"';
    }

    $httpResponse->setHeader('Content-Disposition', $attachment);

    $data = $this->formatCsv();

    // fix line endings
    if ($this->line_endings == self::CRLF) {
      $data = str_replace("\n", "\r\n", str_replace("\r", '', $data));
    }

    $httpResponse->setHeader('Content-Length', strlen($data));
    print $data;

  }

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.