Você está na página 1de 6

CSV Emitter Plugin for BIRT

User Guide
V 1.1
Author: Maneesh Sethi

Version History

Date
25-Sep2011
03-Oct2011

Version No
1.0

Comments
First version of CSV Emitter Plugin for BIRT

1.1

Updated with new CSV Render Options

CSV Render Options


This section explains the Render Options exposed by CSV Emitter.

OUTPUT_FILE_NAME - This option can be used to specify the directory


and filename to output the report. Default filename is report.csv in the
current directory.
USAGE - csvOptions.setOutputFileName ("reports/csvTest.csv");

EXPORT_TABLE_BY_NAME This render option can be used to specify a


specific table name to output. If the table name provided in this option
is not found in the report design the output will be blank file.
If this option is not set, default behaviour is to use the first table in the
report design.
USAGE - csvOptions.setExportTableByName ("SecondTable");

SHOW_DATATYPE_IN_SECOND_ROW - This render option can be used to


specify is the Data Type of columns in a table will be rendered in the
output in the second row.
Default is set to false.
USAGE - csvOptions.setShowDatatypeInSecondRow (true);

DELIMITER This render option can be used to specify the text and
field delimiter to be used in the report output.
Default is set to comma.
USAGE - csvOptions.setDelimiter("\t");

REPLACE_DELIMITER_INSIDE_TEXT_WITH This render options can be


used to specify a character or string to be replaced with delimiter if in
case delimiter appears in actual text field.
Default is set to blank space.
USAGE - csvOptions.setReplaceDelimiterInsideTextWith("-");

Sample Test Program


This sample program can be used to run a report to render output in CSV
Format.
BIRT Runtime is a prerequisite to use this program.

import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.emitter.csv.CSVRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
public class RunReport {
public static void runReport() throws Exception {
IReportEngine engine = null;
EngineConfig config = new EngineConfig();
// Your BIRT Runtime Directory Path, don't include ReportEngine in path
name
config.setEngineHome("D:/BIRTRuntime/birt-runtime-3_7_0/");
config.setLogConfig("D:/birt/logs", Level.FINE);
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_
REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
engine.changeLogLevel(Level.WARNING);
// Your Report Design File Name here..
IReportRunnable design =
engine.openReportDesign("new_report_1.rptdesign");
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
// Creating CSV Render Option object here..
CSVRenderOption csvOptions = new CSVRenderOption();

String format = CSVRenderOption.OUTPUT_FORMAT_CSV;


// Setting up various CSV Render Option before running the task
// CSV Render Option to set the output format
csvOptions.setOutputFormat(format);
// CSV Render Option to specify the output directory and file
csvOptions.setOutputFileName("reports/csvTest.csv");
// CSV Render Option to set if Data Type of column need to be rendered in
second row of output
csvOptions.setShowDatatypeInSecondRow(true);
// CSV Render Option to Render a Table by Name
csvOptions.setExportTableByName("SecondTable");
// CSV Render Options to specify the delimiter
csvOptions.setDelimiter("\t");
// CSV Render Option to specify the character to be replaced if delmiter
appears in actual text
csvOptions.setReplaceDelimiterInsideTextWith("-");
task.setRenderOption(csvOptions);
task.setEmitterID("org.eclipse.birt.report.engine.emitter.csv");
task.run();
task.close();
Platform.shutdown();
System.out.println("Report Generated Sucessfully!!");
}
public static void main(String[] args) {
try {
runReport();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Você também pode gostar