Example #1
0
 public function CSVDump()
 {
     $filter->login = $this->data->login;
     $result = Usuario::create()->listByFilter($filter)->asQuery()->getResult();
     $csvdump = new MCSVDump();
     $file = $csvdump->save($result, 'exemplo.csv');
     $this->data->url = $file->getURL();
     $this->render("formcsvdump");
 }
 function fillCSV($array, $fileInput, $fileOutput, $fileType, $parameters, $classPath, $save)
 {
     $params = $this->prepareParameters($parameters);
     $params->put('REPORT_LOCALE', new Java("java.util.Locale", 'pt', 'BR'));
     $extension = substr($fileInput, strrpos($fileInput, '.'));
     try {
         $sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
         if ($extension == ".jrxml") {
             $s1 = new JavaClass("net.sf.jasperreports.engine.xml.JRXmlLoader");
             $jasperDesign = $s1->load($fileInput);
             $sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
             $report = $sJcm->compileReport($jasperDesign);
         } else {
             $report = $fileInput;
         }
         $csvDump = new MCSVDump(Manager::getOptions('csv'), MCSVDump::WINDOWS_EOL);
         $fileCSV = str_replace('.pdf', '.csv', $fileOutput);
         $csvDump->save($array, basename($fileCSV));
         $sJds = new Java("net.sf.jasperreports.engine.data.JRCsvDataSource", $fileCSV, 'UTF8');
         $sJds->setFieldDelimiter(Manager::getOptions('csv'));
         $print = $sJfm->fillReport($report, $params, $sJds);
         $sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
         $output = \Manager::getDownloadURL('report', basename($this->fileOutput), true);
         $sJem->exportReportToPdfFile($print, $fileOutput);
     } catch (Exception $e) {
         dump_java_exception($e);
     }
     return $output;
 }
Example #3
0
 public function asCSV($showColumnName = false)
 {
     $this->getResult();
     $result = $this->result;
     if ($showColumnName) {
         for ($i = 0; $i < $this->columnCount; $i++) {
             $columns[] = ucfirst($this->metadata['fieldname'][$i]);
         }
         array_unshift($result, $columns);
     }
     $id = uniqid(md5(uniqid("")));
     // generate a unique id to avoid name conflicts
     $fileCSV = \Manager::getFilesPath($id . '.csv', true);
     $csvDump = new \MCSVDump(\Manager::getOptions('csv'));
     $csvDump->save($result, basename($fileCSV));
     return $fileCSV;
 }