コード例 #1
0
 /**
  * Exports the given data to a given format
  *
  * @Routing\Route("/api/export", defaults={"method" = "post","_format" = "json"})
  * @View()
  *
  * @return array
  */
 public function exportAction(Request $request)
 {
     $contentTypes = $request->getAcceptableContentTypes();
     $exporter = false;
     $file = tempnam(sys_get_temp_dir(), "partkeepr_export");
     unlink($file);
     foreach ($contentTypes as $contentType) {
         switch ($contentType) {
             case "text/comma-separated-values":
                 $exporter = new CsvWriter($file, ',', '"', '\\', false);
                 break;
             case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
                 $exporter = new XmlExcelWriter($file, false);
                 break;
         }
     }
     if ($exporter === false) {
         throw new \Exception("No or invalid format specified");
     }
     $content = json_decode($request->getContent(), true);
     $exporter->open();
     foreach ($content as $item) {
         $exporter->write($item);
     }
     $exporter->close();
     $exportData = file_get_contents($file);
     return new Response($exportData, 200);
 }
コード例 #2
0
ファイル: XmlExcelWriterTest.php プロジェクト: kazak/forum
 public function testSpecificTypes()
 {
     // define type for specific cell
     $writer = new XmlExcelWriter($this->filename, false, array('year' => 'String', 'surname' => 'Number'));
     $writer->open();
     $writer->write(array('name' => 'john', 'surname' => 'doe ', 'year' => '2001'));
     $writer->close();
     $expected = '<Row><Cell><Data ss:Type="String">john</Data></Cell><Cell><Data ss:Type="Number">doe </Data></Cell><Cell><Data ss:Type="String">2001</Data></Cell></Row>';
     $this->assertTrue(strstr(file_get_contents($this->filename), $expected) !== false);
 }