ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Editors / Report editor / Data sources
  • Overview
  • Using the wizard for creating a report based on a text file
  • Creating a report based on a text file with automatic reading of records
  • Characteristics of the text file when deploying the application
  • Programming the read operations performed on the records
  • Overview
  • Creating a report based on a text file with programmed reading of records
  • Programming the reading of records
  • Order of execution of the different WLanguage events
  • Modifying the method for reading records of a report based on a text file
  • Printing a report based on a text file
  • WINDEV and WINDEV Mobile example
  • WEBDEV example
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Report based on a text file
Overview
In a report based on a text file, the information to print is read from a text file or is directly assigned in the report controls.
This type of report is convenient when the information to print is found in a text file (data exported from Excel for example).
Characteristics of a report based on a text file: Each line found in the text file must correspond to a record. Each line contains various information, called items. The items are separated by a separator.
To create a report from a text file, you can:
  • use the wizard for creating a report based on a text file. The report editor automatically creates the report and reads the records. No programming is required.
  • program the read operation performed on the records. The report creation wizard makes creating reports much easier. However, reading records in a text file requires a full programming in WLanguage.
Once the report based on a text file is created, you can:
  • change the data source of the report ("Data" tab in the report description).
  • modify the method for reading the records found in the report (automatic or programmed). For more details, see "Modifying the method for reading the records of a report based on a text file".
  • add or delete Item controls linked to the text file associated with the report.
Using the wizard for creating a report based on a text file

Creating a report based on a text file with automatic reading of records

To create a report based on a text file with automatic reading of records:
  1. Click in the quick access buttons.
    • The new element window appears: click "Report" then "Report".
    • The report creation wizard starts.
  2. Choose the layout of your report (table, form, label, ...). For more details, see The different types of reports.
  3. Select (if necessary) the report template to use. A report template is used to comply with a specific page layout. For more details on report templates, see Report templates.
  4. Select the data source of the report ("Other (programing, text file, memory area, HFSQL view, etc.)").
  5. Select the data source of the report ("From a text file").
  6. Select "I want everything to be automatic".
  7. Specify the number of items found in the text file. This number corresponds to the number of information found in each record.
  8. Specify the separator that will be used to separate the record items:
    • "TAB" if the separator corresponds to a tabulation.
    • ";" if the separator corresponds to a semicolon.
    • ":" if the separator corresponds to a colon.
    • ...
  9. Select the text file containing the records.
    Remarks:
    • The captions of the items must not be specified in this text file. For example:
    • When deploying an application containing a report based on a text file with automatic reading of records, some rules must be complied with. See "Characteristics of the text file when deploying the application" for more details.
  10. For each item of the text file displayed in the report:
    • type the corresponding caption. This caption will be displayed:
      • before the item. For example:
      • in the column header (for the Table reports). For example:
        This caption can be modified in the report editor.
    • select the block where the control associated with the item will be printed. The positions of different controls can be modified in the report editor. For more details on the different blocks and their position in a report, see Report blocks.
  11. Modify (if necessary) the display order of controls in the report with the arrow buttons found on the right of table.
  12. Depending on the type of report currently created, indicate the specific options.
    Type of reportSpecific options
    Report based on a formForm image, printing the form image, ...
    Options presented in detail in Report based on a form
    Label reportFormat of labels, number of identical copies, ...
    Options presented in detail in Label report
  13. Specify the format of sheet on which the report will be printed. The report is printed in A4 format by default.
    Remark: By default, the report controls are displayed in a single column. To create a multi-column report, simply specify the desired number of columns in the "Format" tab of the report description window.
  14. Select the skin template of the report if necessary.
  15. Type the name and title of the report (name of ".WDE" file corresponding to the report). This name will be used to identify the report in your programs.
    WINDEV You can also specify whether the report can be modified by the end user in "Reports & Queries".
  16. Validate the report creation.
  17. The report editor automatically proposes to change the report format if the following conditions are fulfilled:
    • the report currently created includes a table.
    • the report format does not allow to display all table columns.
  18. Specify (if necessary) the mode for reducing the report size:
    • Print the report on several pages. In this case, the end user will have to group the pages. For more details, see Multi-page print.
    • Use the landscape mode.
    • Reduce the report size. Caution: according to the reduction percentage, the printed report may become unreadable.
  19. The report currently created is displayed in the report editor.

Characteristics of the text file when deploying the application

When deploying an application containing a report based on a text file, the following cases may occur:
  • If the text file is supplied with the application, we recommend that you include this text file in the application library.
    Caution: The content of this file cannot be modified on the end-user computer.
  • If the content of the text file might be modified on the end-user computer, when printing the report, the text file will be sought on the end-user computer according to the following order:
    1. in the libraries associated with the application and loaded into memory upon report printing.
    2. in the directory specified when creating the report.
    3. in the current directory.
    4. in the application's setup directory.
  • If the text file specified when creating the report differs from the one used by the end user (different name and path), the user will have to select the file via a file picker. Once the text file is selected, the following operations can be performed:
    • send the name and path of the text file selected by the user into a variable.
    • modify the data source of the report with the SourceName property.
Programming the read operations performed on the records

Overview

To create a report based on a text file while programming the read operations performed on the records, two steps are required:
  1. Creating the report with the creation wizard.
  2. Programming the reading of records.

Creating a report based on a text file with programmed reading of records

To create a report based on a text file with programmed reading of records:
  1. Click in the quick access buttons.
    • The new element window appears: click "Report" then "Report".
    • The report creation wizard starts.
  2. Choose the layout of your report (table, form, label, ...). For more details, see The different types of reports.
  3. Select (if necessary) the report template to use. A report template is used to comply with a specific page layout. For more details on report templates, see Report templates.
  4. Select the data source of the report ("Other (programing, text file, memory area, HFSQL view, etc.)").
  5. Select the data source of the report ("From a text file").
  6. Select "I want to program the reading of my file".
  7. If the report currently created:
    • includes a table (Table report or Table + Chart report):
      • specify the number of columns found in the table.
      • for each column, specify the caption and type of the printed value.
      • modify (if necessary) the order of the different columns.
    • is a report based on a form, you must specify the options specific to the form (image of the form, print of the form image, ...). These options are presented in Report based on a form.
    • is a Label report, you must specify the options specific to the labels (format of labels, number of identical copies, etc.). These options are presented in Label report.
  8. Specify the format of sheet on which the report will be printed. The report is printed in A4 format by default.
    Remark: By default, the report controls are displayed in a single column. To create a multi-column report, simply specify the desired number of columns in the "Format" tab of the report description window.
  9. Select the skin template of the report if necessary.
  10. Type the name and title of the report (name of ".WDE" file corresponding to the report). This name will be used to identify the report in your programs.
    WINDEV You can also specify whether the report can be modified by the end user in "Reports & Queries".
  11. Validate the report creation.
  12. The report editor automatically proposes to change the format of the report and/or to reduce the table if the following conditions are fulfilled:
    • the report format does not allow to display all table columns.
    • the report currently created includes a table.
  13. Specify (if necessary) the mode for reducing the report size:
    • Print the report on several pages. In this case, the end user will have to group the pages. For more details, see Multi-page print.
    • Use the landscape mode.
    • Reduce the report size. Caution: according to the reduction percentage, the printed report may become unreadable.
  14. The report currently created is displayed in the report editor.

Programming the reading of records

The programming required for reading the records is illustrated in the following example:

The information to be printed is contained in the .TXT product file. Each line in the file corresponds to a record. The data is displayed in the item controls. The different items are separated by tabulations ("TAB").

The following method is used to program the reading of records:
  1. Open the text file in the "Open" event of the report (fOpen).
    Remark: The captions of the items must not be specified in this text file.
    GLOBAL
    gfsLine is string = ""
    gfnFileID is int = 0    // Identifier of the text file
    LOCAL
    sTextFile is string = fCurrentDir() + "\Reports\Product.txt"
    gfnFileID = fOpen(sTextFile, foRead)    // Open the text file
    IF gfnFileID = -1 THEN
    Error(ErrorInfo())
    iCloseReport()      // Stop the report process
    END
  2. In the "Reading the report data" event:
    • Read each line of the text file (fReadLine).
    • Check whether the end of file was reached. The following values are returned according to the case:
      • True: end of file not reached (step 3 is run).
      • False: end of file reached (step 4 run).
        // Extract the data from the file and display it in the report
        gfsLine = fReadLine(gfnFileID)
        // End of file reached?
        IF gfsLine = EOT OR gfsLine = "" THEN
        RESULT False
        ELSE
        RETURN True
        END
  3. The event "Before printing" of the BODY block is used to manage the file records:
    • Extract the different items from the current record (ExtractString).
    • Assign the extracted values into the report controls.
      nPrice is int = 0
      nPrice = ExtractString(gfsLine, 4, TAB)
      // Initialize the table columns
      ITEM_Reference = ExtractString(gfsLine, 2, TAB)
      ITEM_Description = ExtractString(gfsLine, 3, TAB)
      ITEM_Price = nPrice
      ITEM_BarCode = ExtractString(gfsLine, 5, TAB)
      ITEM_Family = ExtractString(gfsLine, 6, TAB)
  4. The "Close" event of the report is used to close the text file when the end of this file has been reached (fClose).
    // Close the file
    fClose(gfnFileID)

Order of execution of the different WLanguage events

The order in which the different WLanguage events are executed to read the records is presented in the following table:
Order of execution of report eventsProgramming required for reading the text file
1. Opening the reportOpen the text file (fOpen).
2. Reading the report dataRead each line of the text file (fReadLine) and manage the end of the text file.
3. Before printing the Body blockExtract the different items from the current record (ExtractString) and assign their values into the report controls.
4. Closing the reportClose the text file (fClose).
Modifying the method for reading records of a report based on a text file
Once the report based on a text file has been created, you have the ability to modify the method used for reading the records (automatic or programmed read operation).
This method is described in the "Data" tab of the report description.
To switch from an automatic read operation to a programmed read operation:
  1. Open the report description window using one of the following methods:
    • "Report description" in the context menu of the report.
    • on the "Modification" tab, click the dialog box launcher of the "Report" group.
  2. Go to the "Data" tab of the report description.
  3. Check "I want too program the reading of my file".
  4. Program the reading of records. For more details, see Programming the reading of records.
To switch from a programmed read operation to an automatic read operation:
  1. Open the report description window using one of the following methods:
    • "Report description" in the context menu of the report.
    • on the "Modification" tab, click the dialog box launcher of the "Report" group.
  2. Go to the "Data" tab of the report description.
  3. Check "All automatic".
  4. Specify the number of items found in the text file.
  5. Specify the separator that will be used to separate the different items:
    • "TAB" if the separator corresponds to a tabulation.
    • ";" if the separator corresponds to a semicolon.
    • ":" if the separator corresponds to a colon.
    • ...
  6. Select the text file containing the records.
    Remarks:
  7. Delete all the code lines specific to the reading of records.
Printing a report based on a text file
Printing a report from a text file is the same regardless of the method used to read the records (automatic or programmed). To do so:
  1. Configure the report print destination:
    • WINDEV In WINDEV, with iDestination (report viewer, print in an HTML file, etc.).
    • WEBDEV - Server code In WEBDEV, with iDestination (print in an HTML file, etc.).
    For more details, see Print modes of a report.
  2. Specify the name of the report to print with iPrintReport.
Remarks:
  • If additional parameters must be passed to the report, these parameters must be specified in iPrintReport, after the name of the report to print.
  • When used in the code of the report, the SourceName property allows you to get and change the name of the text file associated with the report (when records are read automatically).
In Reports & Queries, you can print a report:
  • by starting a print job ().
  • by testing the report ().
Therefore, no programming is required to print the report.
WINDEVReports and QueriesWindows

WINDEV and WINDEV Mobile example

The "RPT_Customer" report is based on the "Customer.TXT" text file. This text file contains the characteristics of customers.
The "RPT_Customer" report is printed when the "BTN_Customer" button is clicked on.
In this example, the click code of "BTN_Customer" is as follows:
WINDEV WINDEV code:
// Open report viewer
iDestination(iViewer)
// Print the RPT_Customer report
iPrintReport(RPT_Customer)
WEBDEV - Server code

WEBDEV example

The "RPT_Customer" report is based on the "Customer.txt" text file. This text file contains the characteristics of customers. This file is accessible from the server.
The "RPT_Customer" report is displayed in a PDF file when the "BTN_Customer" button is clicked on.
In this example, the click code of "BTN_Customer" is as follows:
// Generates a unique PDF file name
UniqueFileName is string = fWebDir() + "\" + "RPT_Customer_" + DateSys() + TimeSys() + ".pdf"
// Configures the print destination
iDestination(iPDF, UniqueFileName)
// Prints the RPT_Customer report
iPrintReport(RPT_Customer)
// Sends the file to the browser
FileDisplay(UniqueFileName, "application/pdf")
// Deletes the file
fDelete(UniqueFileName)
Related Examples:
WD Reports Training (WINDEV): WD Reports
[ + ] This example presents the different methods for creating a report:

- prints based on different data sources (queries, variables, ...)
- prints based on controls (Table, Spreadsheet, PVT, ...)
- printing composite reports
- specific prints (portrait/landscape, report with watermark, report with bar code, ...)
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/30/2023

Send a report | Local help