To export a text file in JReport Designer, on the File menu, point to Export, and then click To Text. The Export to Text dialog appears.
The Export To Text dialog includes the following screen elements:
Export to
Type the file name and directory where you want to store the exported text file or click the Browse button to specify the directory.Standard Data Format
This section allows you to specify the format in the following options.Format
You can specify a delimiter to separate fields. Select one from the drop-down list.CSV Delimited - Fields in the exported text file will be separated by commas.
Tab Delimited - Fields in the exported text file will be separated by tabs.
Custom Delimited - Fields in the exported text file will be separated by a user defined delimiter. You can type your own delimiter in the Delimiter box.
QuoteMark
If checked, fields in the exported text file will be marked with quotation marks.
Header and Footer
If checked, the exported file will contain all headers and footers in the report, including Report Header/Footer, Page Header/Footer and Group Header/Footer. Otherwise, the exported file will only contain data in the Detail section.
Repeat last column value if null
If checked, when a certain field has no value, it will repeat the data of the previous record.User Define Density
This section allows you to specify the density for the exported text file content.Horizontal Density
Type a value for each unit of the horizontal density between columns. The density of the result is in direct ratio to the value you specified. That is to say, the greater the value is, the smaller the width between columns. The default value is -1.
Vertical Density
Type a value for each unit of the vertical density between columns. The density of the result is in direct ratio to the value you specified. That is to say, the greater the value is, the smaller the height between columns. The default value is -1.Compress
If checked, there is no clearance between columns. Please note that, this option works only when no any data (including empty strings) display in a row (since JReport Designer v4.5).Resolution
Specify resolution as you desired. When the value is -1, it will use the current resolution of your monitor.Use Windows end-of-line characters
Specifies whether to use Windows end-of-line characters to indicate the start of a new line. If checked, it uses two characters at the end of the line: <cr><lf>. Otherwise, it uses Unix EOL character: <lf>, at the end of line.
The following case is a simple example to show you how to export your report to a csv format file:
- Open the report to be exported. Here we select the demo report
Lesson2.clsunder%Intall_Root%\demo\reports.- On the File menu, point to Export, and then click To Text.
- Specify the destination of the exported file:
C:\rptcsv\lesson2.csv. Check Standard Data Format, select CSV Delimited from the Format drop-down list.- To have records aligned well in the exported file, you are suggested checking QuoteMark. If not, the commas in the data value like "$78,321.00" will conflict with the delimiter (comma), and may potentially cause the data to be separated incorrectly when the exported file is further processed by other applications.
"Scarsdale,The Java King,(914) 657-9823,(914) 657-8745,$78,321.00"
As shown above, it's hard to determine whether the value is $78321.00 or $78 and 321.00.- Click OK to perform the exporting operation.
Notes:
- In the exported file, you may find that some column names are not aligned with their DBFields. They may display in different columns. To solve the problem, make both the column name and its DBField left aligned and adjust their location with the same Geometry "X" before exporting it to the CSV format.
For example, as the image below:
1. Select both column name "City" and its DBField.
2. On the Format toolbar, click the Left button. This makes the text "City" and "XXXXXXXXXX" align left.
3. On the Format menu, click Align Left. This makes the label and DBField align left.
- In step 4 above, you can also use other delimiters such as "|". However, when you do so, you should export to .txt file instead of .csv file. Open it in Excel. In the Text Import wizard, check the Delimited radio button, click Next to go to the next step. Check Other on the Delimiters panel and key in "|" (quotation marks NOT included), click Finish to view the result.
- The data of each field should be in one column. If there are no data in the column, empty strings ("")will be put there automatically. In this case, the empty strings can not be compressed. Only if there are no data in the entire line, can the row be compressed when you check the Compress option.
- When exporting a report to CSV file, you may want to export only some of the objects instead of all.
For example, to export only the DBField "Annual Sales" to a CSV file, follow the procedure below:
1. Select DBField "Annual Sales".
2. On the View menu, check the Report Inspector.
3. In Report Inspector, set ExportToCSV to True.
4. In Design view, select all the other objects you don't want to export.
5. In Report Inspector, set ExportToCSV to False.
6. On the File menu, point to Export, click To Text to export the report.
7. In the Export to text dialog, specify the subdirectory and name of the exported file, make sure that you have checked the Standard Data Format box and selected CSV Delimited format. Click OK.
The exported file will only contain the data of the DBField "Annual Sales". You can control whether to export the other objects to the exported CSV file in the same way. Please note, if you set the ExportToCSV property of a section to be false, all the objects in this section will not be exported regardless of their ExportToCSV properties.To improve the performance of running report to the Standard Data Format on JReport Enterprise Server
On JReport Enterprise Server, if you want to improve the performance of running a report to the Standard Data Format, such as the CSV format, some settings should be done in JReport Designer first and then deploy the report to JReport Enterprise Server to run it to the Standard Data Format. Please follow the steps below:
- Open the report you want to run to the Standard Data Format on the server in JReport Designer. In Report Inspector, browse to the root node of the report, find the two properties FastPass and Columned, and then set them to true.
- Choose the object you want to display in the result file and set where you want them to be shown in the result file. To do this, select the object, and find the two properties ColumnIndex and RowIndex. The ColumnIndex refers to which column this object will be in and the RowIndex refers to which row this object will be in in the result file. The number of the column and the row are started with 0 and counted within its section, for example, if you want to place the object in the first column and the second row in the detail section, set ColumnIndex = 0 and RowIndex = 1 of this object.
Note: This method can also be used in JReport Designer to improve the performance when export the report result to Standard Data Format.- Please go to the server.propertise file under
%JREntServer_InstallRoot%\binto change the property engine.single_thread = false. This enables the property FastPass to take effect when running the report to the Standard Data Format.- Deploy the report to JReport Enterprise Server, when you run or schedule the report, after you choose the To Text format, please select the Standard Data Format check box, and then click Submit to generate the Standard Data Format file.
Notes:
- When the FastPass property is true, in the report header panel, the values of the objects which use the global parameters to do the calculation will be wrong, and the page level calculation, such as Page Number, Total Page Number, will also be wrong. So please move these objects from the report header panel to the report footer panel to avoid these kinds of mistakes.
- Please do set the positions for the objects with the ColumnIndex and RowIndex properties, otherwise, all the objects will be at the first column and the first row in the result file.
- You can not run the report with Cross Tab to the Standard Data Format in this way.
Exporting to JReport Result
Exporting to HTML
Exporting to PDF
Exporting to Fax
Exporting to Postscript File
Exporting to Mail
Exporting to Applet
Exporting to RTF
Exporting to Excel File
Exporting to XML