PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Using the wizard for creating a report on a text file
  • Creating a report 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 on a text file with programmed reading of records
  • Programming the reading of records
  • Runtime order of the different WLanguage processes
  • Modifying the method for reading records of a report on a text file
  • Printing a report 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Report on text file
Overview
In a report on a text file, the information to print is read in a file in text format or it 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 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 on 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 wizard for report creation greatly simplifies the creation of reports. However, reading records in a text file requires a full programming in WLanguage.
Once the report on a text file is created, you have the ability to:
  • modify the data source of report ("Data" tab of report description).
  • modify the method for reading the records found in the report (automatic or programmed). See "Modifying the method for reading the records found in a report on a text file" for more details.
  • add or delete Item controls linked to the text file associated with the report.
Versions 18 and later
iPhone/iPad This feature is now available for the iPhone/iPad applications.
New in version 18
iPhone/iPad This feature is now available for the iPhone/iPad applications.
iPhone/iPad This feature is now available for the iPhone/iPad applications.
Versions 21 and later
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
Using the wizard for creating a report on a text file

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

To create a report on a text file with automatic reading of records:
  1. Select "File .. New .. Report". The wizard for report creation starts.Click among the quick access buttons.
    • Click "Report" in the wheel that is displayed. The window for creating a new element is displayed: click "Report" then "Report".
    • The wizard for report creation starts.
  2. Choose the layout of your report (table, form, label, ...). See The different types of reports for more details.
  3. Select (if necessary) the report template to use. A report template is used to comply with a specific page layout. See The report templates for more details.
  4. Select the data source of the report ("Other (programing, text file, memory zone, HyperFileSQL view, ...)"). Select the data source of the report ("Other (programing, text file, memory zone, HFSQL view, ...)").
  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.
    Notes:
    • 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. See Report blocks for more details.
  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
    Type of report: Table + ChartType of chart, aspect of chart, ...
    Options presented in Table + Chart report
    Chart reportType of chart, aspect of chart, ...
    Options presented in Chart report
    Report on formForm image, printing the form image, ...
    Options presented in Report on form
    Label reportFormat of labels, number of identical copies, ...
    Options presented in Label report
    Type of reportSpecific options
    Report on formForm image, printing the form image, ...
    Options presented in Report on form
    Label reportFormat of labels, number of identical copies, ...
    Options presented in Label report
  13. Specify the format of the sheet on which the report will be printed. The report is printed in A4 format by default.
    Note: By default, the report controls are displayed in a single column. To create a multi-column report, the requested number of columns must be specified in the "Format" tab of the description window of report.
  14. Select the skin template of report if necessary.
  15. Type the name and title of report (name of ".WDE" file corresponding to the report). This name will be used to identify the report in your programs.
    WINDEV You also have the ability to 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 the table columns.
  18. Specify (if necessary) the mode for reducing the report size:
    • Versions 19 and later
      Print the report on several pages. In this case, the end user will have to group the pages. See Multi-page print for more details.
      New in version 19
      Print the report on several pages. In this case, the end user will have to group the pages. See Multi-page print for more details.
      Print the report on several pages. In this case, the end user will have to group the pages. See Multi-page print for more details.
    • 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 during report creation.
    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 ..SourceName.
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 on a text file with programmed reading of records

To create a report on a text file with programmed reading of records:
  1. Select "File .. New .. Report". The wizard for report creation starts.Click among the quick access buttons.
    • Click "Report" in the wheel that is displayed. The window for creating a new element is displayed: click "Report" then "Report".
    • The wizard for report creation starts.
  2. Choose the layout of your report (table, form, label, ...). See The different types of reports for more details.
  3. Select (if necessary) the report template to use. A report template is used to comply with a specific page layout. See The report templates for more details.
  4. Select the data source of the report ("Other (programing, text file, memory zone, HyperFileSQL view, ...)"). Select the data source of the report ("Other (programing, text file, memory zone, HFSQL view, ...)").
  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 on 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 on form.
    • is a Label report, you must specify the options specific to the labels (format of labels, number of identical copies, ...). These options are presented in Label report.
      • is a Chart report, you must specify the options specific to the chart (type of chart, aspect of the chart, ...). These options are presented in Chart report.
      • is a Table + Chart report, you must specify the options specific to the chart (type of chart, aspect of the chart, ...). These options are presented in Table + Chart report.
  8. Specify the format of the sheet on which the report will be printed. The report is printed in A4 format by default.
    Note: By default, the report controls are displayed in a single column. To create a multi-column report, the requested number of columns must be specified in the "Format" tab of the description window of report.
  9. Select the skin template of report if necessary.
  10. Type the name and title of report (name of ".WDE" file corresponding to the report). This name will be used to identify the report in your programs.
    WINDEV You also have the ability to 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 the table columns.
    • the report currently created includes a table.
  13. Specify (if necessary) the mode for reducing the report size:
    • Versions 19 and later
      Print the report on several pages. In this case, the end user will have to group the pages. See Multi-page print for more details.
      New in version 19
      Print the report on several pages. In this case, the end user will have to group the pages. See Multi-page print for more details.
      Print the report on several pages. In this case, the end user will have to group the pages. See Multi-page print for more details.
    • 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 "Opening" process of the report (fOpen).
    Note: 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" process:
    • 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
        RESULT True
        END
  3. The "Before printing" process 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 "Closing" process 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)

Runtime order of the different WLanguage processes

The runtime order of the different WLanguage processes used to read the records are presented in the following table:
Runtime order of the report processesProgramming 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 on a text file
Once the report on a text file is 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. Display the description window of report by using one of the following methods:
    • "Report description" from the popup menu of the report.
    • "Report .. Report description".on the "Modification" pane, click the group icon of the "Report" group.
  2. Display the "Data" tab of the report description.
  3. Check "I want too program the reading of my file".
  4. Program the reading of records. See Programming the reading of records for more details.
To switch from a programmed read operation to an automatic read operation:
  1. Display the description window of report by using one of the following methods:
    • "Report description" from the popup menu of the report.
    • "Report .. Report description".on the "Modification" pane, click the group icon of the "Report" group.
  2. Display 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.
    Notes:
  7. Delete all the code lines specific to the reading of records.
Printing a report on a text file
Printing a report based on a text file is identical regardless of the method used to read the records (automatic or programmed). All you have to do is:
  1. Configure the destination of report print:
    • WINDEV In WINDEV, with iPreview (print preview, print in an HTML file, ...).
    • WEBDEV - Server code In WEBDEV, with iDestination (print in an HTML file, ...).
    • Windows Mobile In Windows Mobile, with iConfigure or iParameter. These functions open a dialog box allowing the user to select the default printer.
      See Print modes of report for more details.
  2. Specify the name of report to print with iPrintReport.
Notes:
  • If additional parameters must be passed to the report, these parameters must be specified in iPrintReport, after the name of the report to print.
  • ..SourceName used in the report code allows you to find out and change the name of the text file associated with the report (if the records are automatically read).

Important

In Reports & Queries, a report can be printed:
  • by starting a print ( ).
  • by running the report test ( ).
Therefore, no programming is required to print the report.
WINDEVReports and QueriesWindowsWindows Mobile

WINDEV and WINDEV Mobile example

The "RPT_Customer" report is based on the "Customer.TXT" text file. This text file contains the characteristics of the customers.
The "RPT_Customer" report is printed during a click on the "BTN_Customer" button.
In this example, the click code of "BTN_Customer" is as follows:
WINDEV WINDEV code:
// Open the preview window
iPreview()
// Print the RPT_Customer report
iPrintReport(RPT_Customer)
Windows Mobile Windows Mobile code:
// Select the printer
iConfigure()
// 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 the customers. This file is accessible from the server.
The "RPT_Customer" report is displayed in a PDF file during a click on the "BTN_Customer" button.
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 required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment