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

项目:openbravo-brazil    文件:ReportingUtils.java   
/**
 * Generates a plain text report from a pre-compiled report and returns it into a file.
 * 
 * @param jasperPrint
 *          JasperPrint object which contains a compiled report.
 * @param file
 *          The file used to return the report.
 * @throws JRException
 *           In case there is any error generating the report an exception is thrown with the
 *           error message.
 */
private static void saveTxtReportToFile(JasperPrint jasperPrint, File file) throws JRException {
  final JRTextExporter textExporter = new JRTextExporter();
  SimpleExporterInput exporterInput = new SimpleExporterInput(jasperPrint);
  SimpleWriterExporterOutput exporterOutput = new SimpleWriterExporterOutput(file);

  // Default text configuration that can be overridden in the .jrxml template itself
  SimpleTextExporterConfiguration textExporterConfiguration = new SimpleTextExporterConfiguration();
  textExporterConfiguration.setOverrideHints(false);
  textExporter.setConfiguration(textExporterConfiguration);
  // Default item text configuration that can be overridden in the .jrxml template itself
  SimpleTextReportConfiguration textReportConfiguration = new SimpleTextReportConfiguration();
  textReportConfiguration.setCharHeight(new Float(TEXT_CHAR_HEIGHT));
  textReportConfiguration.setCharWidth(new Float(TEXT_CHAR_WIDTH));
  textReportConfiguration.setOverrideHints(false);
  textExporter.setConfiguration(textReportConfiguration);

  textExporter.setExporterInput(exporterInput);
  textExporter.setExporterOutput(exporterOutput);
  textExporter.exportReport();
}
项目:openbravo-brazil    文件:ReportingUtils.java   
/**
 * Generates a plain text report from a pre-compiled report and returns it into an output stream.
 * 
 * @param jasperPrint
 *          JasperPrint object which contains a compiled report.
 * @param outputStream
 *          The output stream used to return the report.
 * @throws JRException
 *           In case there is any error generating the report an exception is thrown with the
 *           error message.
 */
private static void saveTxtReportToOutputStream(JasperPrint jasperPrint, OutputStream outputStream)
    throws JRException {
  final JRTextExporter textExporter = new JRTextExporter();
  SimpleExporterInput exporterInput = new SimpleExporterInput(jasperPrint);
  SimpleWriterExporterOutput exporterOutput = new SimpleWriterExporterOutput(outputStream);

  // Default text configuration that can be overridden in the .jrxml template itself
  SimpleTextExporterConfiguration textExporterConfiguration = new SimpleTextExporterConfiguration();
  textExporterConfiguration.setOverrideHints(false);
  textExporter.setConfiguration(textExporterConfiguration);
  // Default item text configuration that can be overridden in the .jrxml template itself
  SimpleTextReportConfiguration textReportConfiguration = new SimpleTextReportConfiguration();
  textReportConfiguration.setCharHeight(new Float(TEXT_CHAR_HEIGHT));
  textReportConfiguration.setCharWidth(new Float(TEXT_CHAR_WIDTH));
  textReportConfiguration.setOverrideHints(false);
  textExporter.setConfiguration(textReportConfiguration);

  textExporter.setExporterInput(exporterInput);
  textExporter.setExporterOutput(exporterOutput);
  textExporter.exportReport();
}
项目:jasperreports    文件:TextApp.java   
/**
 *
 */
public void text() throws JRException
{
    long start = System.currentTimeMillis();
    JRTextExporter exporter = new JRTextExporter();
    File sourceFile = new File("build/reports/TextReport.jrprint");
    JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);
    File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".txt");

    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile));
    exporter.exportReport();

    System.err.println("Text creation time : " + (System.currentTimeMillis() - start));
}
项目:nextreports-server    文件:JasperReportsUtil.java   
public static byte[] getTxt(JasperPrint jasperPrint)
        throws JRException {

    byte[] content = null;
    ByteArrayOutputStream baos = null;
    try {
        baos = new ByteArrayOutputStream();
        JRTextExporter exporter = new JRTextExporter();

        exporter.setParameter(JRTextExporterParameter.PAGE_WIDTH, JasperUtil.TXT_PAGE_WIDTH);
        exporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT, JasperUtil.TXT_PAGE_HEIGHT);

        content = getBytes(exporter, baos, jasperPrint);
    } finally {
        if (baos != null) {
            try {
                baos.flush();
                baos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return content;
}
项目:laboratorioSpring    文件:ReportJR.java   
private static JRExporter getJREXporter(final String extension) {
        if ("pdf".equalsIgnoreCase(extension)) {
            JRPdfExporter exporter = new JRPdfExporter();
//          exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print();");

            return exporter;

        } else if ("html".equalsIgnoreCase(extension)) {
            return new JRHtmlExporter();

        } else if ("xls".equalsIgnoreCase(extension)) {
             JRXlsExporter exporterXLS = new JRXlsExporter();                
             exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
             exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
             exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
             exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);

            return exporterXLS;

        } else if ("txt".equalsIgnoreCase(extension)) {
            return new JRTextExporter();
        } else if ("csv".equalsIgnoreCase(extension)) {
            return new JRCsvExporter();
        } else if ("docx".equalsIgnoreCase(extension)) {
            return new JRDocxExporter();
        }
        return null;
    }
项目:PDFReporter-Studio    文件:ExportAsTextAction.java   
@Override
protected JRTextExporter getExporter(JasperReportsConfiguration jContext, JRExportProgressMonitor monitor, File file) {
    JRTextExporter exp = new JRTextExporter(jContext);
    exp.setExporterOutput(new SimpleWriterExporterOutput(file));

    exp.setConfiguration(new SimpleTextExporterConfiguration());

    SimpleTextReportConfiguration rconf = new SimpleTextReportConfiguration();
    setupReportConfiguration(rconf, monitor);
    exp.setConfiguration(rconf);

    return exp;
}
项目:gnvc-ims    文件:OOReportGenerator.java   
private void exportToTxt() {
    //log.debug("exporting to TXT");
    // textExporter = new JRTextExporter();
    // setExportParameter(JRTextExporterParameter.CHARACTER_WIDTH, new
    // Integer(13));
    // setExportParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new
    // Integer(20));

    textExporter = new JRTextExporter();
    if (getJasperReport().hasProperties()) {
        if (null != getJasperReport().getProperty("export.txt.page_rows")) {
            setExportParameter(JRTextExporterParameter.CHARACTER_WIDTH,
                    getJasperReport().getProperty("export.txt.character_width"));
        }
        if (null != getJasperReport().getProperty("export.txt.page_columns")) {
            setExportParameter(JRTxtExporterParameter.PAGE_COLUMNS,
                    getJasperReport().getProperty("export.txt.page_columns"));
        }
        if (null != getJasperReport().getProperty(
                "export.txt.add_form_feed")) {
            setExportParameter(JRTxtExporterParameter.ADD_FORM_FEED,
                    new Boolean(getJasperReport().getProperty(
                    "export.txt.add_form_feed")));
        }
    }
    textExporter.setParameters(getExportParameters());
    try {
        start = System.currentTimeMillis();
        textExporter.exportReport();
        //log.info("export running time (msec): "
        //        + (System.currentTimeMillis() - start));
    } catch (JRException jre) {

        jre.printStackTrace();
    }
}
项目:nextreports-server    文件:JasperReportsUtil.java   
public static void toTxtFile(JasperPrint jasperPrint, Map exporterParams, String txtFile) throws JRException {
    System.out.println("JasperUtil.toTxtFile");

    Timer timer = new Timer();
    timer.start();

    JRTextExporter exporter = new JRTextExporter();
    exporter.setParameters(exporterParams);
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, txtFile);
    exporter.exportReport();

    timer.end();
    System.out.println("To txt in " + timer.duration());
}
项目:openbravo-brazil    文件:ReportingUtils.java   
/**
 * Generates a plain text report using the SimpleExporterInput, SimpleWriterExporterOutput,
 * SimpleTextExporterConfiguration and SimpleTextReportConfiguration received as parameters.
 * 
 * @param exporterInput
 *          SimpleExporterInput object with the input data.
 * @param exporterOutput
 *          SimpleWriterExporterOutput object with the output data.
 * @param textExporterConfiguration
 *          SimpleTextExporterConfiguration with the configuration data.
 * @param textReportConfiguration
 *          SimpleTextReportConfiguration with the item configuration data.
 * @throws JRException
 *           In case there is any error generating the report an exception is thrown with the
 *           error message.
 */
public static void saveTxtReport(SimpleExporterInput exporterInput,
    SimpleWriterExporterOutput exporterOutput,
    SimpleTextExporterConfiguration textExporterConfiguration,
    SimpleTextReportConfiguration textReportConfiguration) throws JRException {
  final JRTextExporter textExporter = new JRTextExporter();
  textExporter.setExporterInput(exporterInput);
  textExporter.setExporterOutput(exporterOutput);
  textExporter.setConfiguration(textExporterConfiguration);
  textExporter.setConfiguration(textReportConfiguration);
  textExporter.exportReport();
}