Java 类net.sf.jasperreports.engine.export.JRCsvExporterParameter 实例源码

项目:gnvc-ims    文件:OOReportGenerator.java   
private void exportToCSV(String delim) {
    log.debug("exporting to CSV. Delimiter char '" + delim + "'");
    csvExporter = new JRCsvExporter();
    setExportParameter(JRCsvExporterParameter.FIELD_DELIMITER, delim);
    setExportParameter(JRCsvExporterParameter.RECORD_DELIMITER, "\r\n");
    csvExporter.setParameters(getExportParameters());
    try {
        start = System.currentTimeMillis();
        csvExporter.exportReport();
        log.info("export running time (msec): "
                + (System.currentTimeMillis() - start));
    } catch (JRException jre) {
        jre.printStackTrace();
        log.error(jre.getCause());
    }
}
项目:spring4-understanding    文件:JasperReportsUtilsTests.java   
@Test
public void renderAsCsvWithExporterParameters() throws Exception {
    StringWriter writer = new StringWriter();
    Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
    exporterParameters.put(JRCsvExporterParameter.FIELD_DELIMITER, "~");
    JasperReportsUtils.renderAsCsv(getReport(), getParameters(), getData(), writer, exporterParameters);
    String output = writer.getBuffer().toString();
    assertCsvOutputCorrect(output);
    assertTrue("Delimiter is incorrect", output.contains("~"));
}
项目:ireport-fork    文件:CSVExportParametersPanel.java   
private void jButtonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonResetActionPerformed

        JRPropertiesUtil jrPropUtils = IRLocalJasperReportsContext.getUtilities();
        JasperReportsContext context = IRLocalJasperReportsContext.getInstance();

        jTextField1.setText( Misc.addSlashesString(jrPropUtils.getProperty(JRCsvExporterParameter.PROPERTY_FIELD_DELIMITER)) );
        jTextField2.setText( Misc.addSlashesString(jrPropUtils.getProperty(JRCsvExporterParameter.PROPERTY_RECORD_DELIMITER)) );
        notifyChange();
    }
项目:ireport-fork    文件:DefaultExporterFactory.java   
private void configureCsvExporter(JRExporter exporter, SimpleJasperReportsContext context) {

        Preferences pref = IReportManager.getPreferences();
        JRPropertiesUtil jrPropUtils = JRPropertiesUtil.getInstance(context);

        context.setValue( JRCsvExporterParameter.PROPERTY_FIELD_DELIMITER, pref.get(JRCsvExporterParameter.PROPERTY_FIELD_DELIMITER, jrPropUtils.getProperty(JRCsvExporterParameter.PROPERTY_FIELD_DELIMITER)));
        context.setValue( JRCsvExporterParameter.PROPERTY_RECORD_DELIMITER, pref.get(JRCsvExporterParameter.PROPERTY_RECORD_DELIMITER, jrPropUtils.getProperty(JRCsvExporterParameter.PROPERTY_RECORD_DELIMITER)));
    }
项目:class-guard    文件:JasperReportsUtilsTests.java   
public void testRenderAsCsvWithExporterParameters() throws Exception {
    StringWriter writer = new StringWriter();
    Map<JRExporterParameter, Object> exporterParameters = new HashMap<JRExporterParameter, Object>();
    exporterParameters.put(JRCsvExporterParameter.FIELD_DELIMITER, "~");
    JasperReportsUtils.renderAsCsv(getReport(), getParameters(), getData(), writer, exporterParameters);
    String output = writer.getBuffer().toString();
    assertCsvOutputCorrect(output);
    assertTrue("Delimiter is incorrect", output.contains("~"));
}
项目:Tanaguru    文件:ExportService.java   
/**
 * Processes the download for Excel format
 *
 * @param response
 * @param resourceId
 * @param auditStatistics
 * @param dataSource
 * @param locale
 * @param format
 * @throws ColumnBuilderException
 * @throws ClassNotFoundException
 * @throws JRException
 * @throws NotSupportedExportFormatException
 */
@SuppressWarnings("unchecked")
public void export(
        HttpServletResponse response,
        long resourceId,
        AuditStatistics auditStatistics,
        Collection<?> dataSource,
        Locale locale,
        String format)
        throws ColumnBuilderException, ClassNotFoundException, JRException, NotSupportedExportFormatException {

    if (!exportFormatMap.containsKey(format)) {
        throw new NotSupportedExportFormatException(format);
    }
    ExportFormat exportFormat = exportFormatMap.get(format);

    DynamicReport dr = LayoutFactory.getInstance().buildReportLayout(locale, auditStatistics, format);
    // Retrieve our data source
    JRDataSource ds = new JRBeanCollectionDataSource(dataSource);

    // params is used for passing extra parameters
    JasperPrint jp
            = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds);

    // Create our output byte stream
    // This is the stream where the data will be written
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    JRExporter exporter = null;
    try {
        exporter = (JRExporter) Class.forName(exportFormat.getExporterClassName()).newInstance();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
        if (exportFormat.getFileType().equals("text/csv")) {
            exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, GENERAL_SEPARATOR_KEY);
        }
        exporter.exportReport();
        response.setHeader(CONTENT_DISPOSITION, INLINE_FILENAME
                + getFileName(resourceId, exportFormat.getFileExtension()));
        // Make sure to set the correct content type
        // Each format has its own content type
        response.setContentType(exportFormat.getFileType());
        response.setContentLength(baos.size());
        // Write to reponse stream
        writeReportToResponseStream(response, baos);
    } catch (InstantiationException | IllegalAccessException ex) {
        LOGGER.warn(ex);
    }

}
项目:ireport-fork    文件:CSVExportParametersPanel.java   
public void load() {

        setInit(true);
        Preferences pref = IReportManager.getPreferences();

        JRPropertiesUtil jrPropUtils = IRLocalJasperReportsContext.getUtilities();

        jTextField1.setText( Misc.addSlashesString(pref.get(JRCsvExporterParameter.PROPERTY_FIELD_DELIMITER, jrPropUtils.getProperty(JRCsvExporterParameter.PROPERTY_FIELD_DELIMITER))));
        jTextField2.setText( Misc.addSlashesString(pref.get(JRCsvExporterParameter.PROPERTY_RECORD_DELIMITER, jrPropUtils.getProperty(JRCsvExporterParameter.PROPERTY_RECORD_DELIMITER))));

        setInit(false);
    }
项目:ireport-fork    文件:CSVExportParametersPanel.java   
public void store() {
    Preferences pref = IReportManager.getPreferences();

    pref.put(JRCsvExporterParameter.PROPERTY_FIELD_DELIMITER, Misc.removeSlashesString( jTextField1.getText()) );
    pref.put(JRCsvExporterParameter.PROPERTY_RECORD_DELIMITER, Misc.removeSlashesString( jTextField2.getText()) );

}