ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

New WINDEV 2024 feature!
Help / WINDEV Tutorial / Tutorial - WINDEV application: Managing data
  • Lesson 4 - Simple printing
  • Overview
  • Printing the contents of a Table control
  • Printing directly via the AAFs (Automatic Application Features)
  • Creating an automatic report based on a Table control
  • Printing a list of customers
  • Creating a report
  • To sum up

Tutorial - WINDEV application: Managing data

Lesson 4 - Simple printing
We will cover the following topics:
  • Printing the content of a Table control.
  • Printing a list of customers.
Durée de la leçon 20 mn
Overview
WINDEV allows you to print your data:
  • through programming.
  • via reports. A report is a graphic representation of a document. Reports are created in the report editor.
We will now explain how to create the different types of reports in "WD Full Application". To do so, we will create:
  • A report to print the contents of a Table control.
  • A report to list customers.
We will also discover how to create a menu in a window. This menu will allows us to print the report.
Printing the contents of a Table control
In the previous lesson, we created a Table control to display the result of a multi-criteria search. Let's take a look at the different methods used to print the content of this Table control.

Printing directly via the AAFs (Automatic Application Features)

In previous lessons, we discovered that WINDEV includes several automatic features (called AAF). One AAF allows you to print the content of a Table control.
Visit https://aaf.windev.com/ to discover the main Automatic Application Features (AAFs). You can automatically access this page via the "Help (AAF)" option in the context menu of any control that uses AAFs.

Let's do a quick test to use this AAF:
  1. Open "WIN_Menu" in the window editor.
  2. Click Test window in the quick access buttons.
  3. Select the "Find orders" tab if necessary.
  4. Define the different search parameters:
    • Order status,
    • Payment method,
    • Range of dates to take into account.
  5. Click "Find".
  6. When the data is displayed in the Table control, open the context menu of the control (click the Control context menu icon at the top right or right-click the control).
  7. Click "Print".
  8. Choose to print the content of the Table control in "Landscape" mode. The report corresponding to the control is displayed in the report viewer.
    Report displayed in the report viewer

    In test mode, the content of the Table control is printed directly.
    At runtime, the end user will be able to print directly, or to start "Reports & Queries" to create the corresponding report. For more details about Reports & Queries, see Distributing Reports and Queries with your applications.
  9. Close the report viewer and stop the application test.
You want to customize the default report? Simply create an automatic report based on the Table control. If the report exists, it will be automatically used by the option for printing the Table control.

Creating an automatic report based on a Table control

If you want to create a report to print the data from a Table control, simply create a "Report based on a Table control": the report corresponding to the Table control is automatically created.
To create a "Report based on a Table control":
  1. Open the "Find orders" tab pane in the window editor.
  2. On the "Creation" tab, in the "Data" group, expand "Table and List Box" and select "Report based on a Table control".
  3. Since this window contains 2 Table controls on different tab panes, WINDEV prompts you to select the desired Table control. In our case, select "TABLE_QRY_FindOrders" and validate.
  4. The shape of a Button control appears under the mouse cursor. This control is automatically created and it contains the WLanguage code used to print the content of the Table control.
  5. Click where you want to create the control in the window (e.g., below the "Find" button, in the "Find orders" tab pane).
  6. The report is automatically created.
  7. A window to save the report appears. Validate.
  8. The report editor appears with the report that was automatically created.
    Report automatically created in the report editor
  9. In this report, you will find the titles of the Table control columns from the window. We will make changes to this report: we will change the title.
    • Select the control that corresponds to the report title ("QRY_FindOrders Table") and double-click on it.
    • In the description window, modify the caption and enter "Sought orders".
    • Validate.
  10. Go back to the "WIN_Menu" window (click "WIN_Menu" in open document tabs).
  11. If necessary, change the size and position of the "Print" button (to match the size of the "Find" Button control).
  12. Save the window by clicking Save an element in the quick access buttons.
  13. Test the window: click Test window in the quick access buttons.
    • Select the "Find orders" tab if necessary.
    • Define the different search parameters:
      • Order status,
      • Payment method,
      • Range of dates to take into account.
    • Click "Find".
  14. When the data is displayed in the Table control, click "Print" or select "Print" in the context menu of the Table control: the report that was just created is used in both cases.
Printing a list of customers
We have seen how reports can be automatically created. However, WINDEV also lets you create reports using the report editor. In this example, we will print a list of customers, grouped by country and by state or province.
To do so, we are going to use a table report in order to clearly represent a list of data.

Creating a report

To create a report:
  1. Click Create an element in the quick access buttons.
  2. The new element window appears: click "Report" then "Report". The report creation wizard starts. The report creation wizard shows several types of reports:
    Report creation wizard - Type of report
  3. Select "Table". Go to the next step.
  4. Select the report data source. The report will be based on the Customer data file. Select "A data file or existing query".
    Report creation wizard - Data source
    Go to the next step.
  5. In the list of data files and queries, select "Customer". Go to the next step.
  6. Define the data file search key. In our case, the Customer data file will be looped through using the customer's full name. Select the "FullName" search key.
    Report creation wizard - Loop through the data file
    Go to the next step.
  7. We will now define the data sorting options in the report. By default, the wizard proposes the item used as search key in the data file. Since we want to create a report to list customers by country and by state, we will add a sort on these two items.
  8. To add a sort on the country:
    • Click the "Add" button and select "Sort criterion" to add a sort item.
    • In the window that appears, select the Customer.Country item.
      Report creation wizard - New sort
    • Validate.
  9. To add a sort on the state:
    • Click the "Add" button and select "Sort criterion" to add a sort item.
    • In the window that appears, select the Customer.StateProvinceRegion item.
    • Validate.
  10. Change the order of the sort items. The customers must be sorted by country, by state, then in alphabetical order.
    • The "Customer.Country" item appears as the second sort item. Select this item and move it to the first position using the "Move up" button.
    • The "Customer.StateProvinceRegion" item appears as the third sort item. Select this item and move it to the second position using the "Move up" button.
      Report creation wizard - Data printing order
      Go to the next step.
  11. The wizard asks you if you want to insert breaks into the report.
    What is a break?
    A Break is an operation used to group the records (or rows) according to one or more criteria. Caution, the records (or rows) will be printed.
    A break is ALWAYS linked to a sort.
    You will notice the presence of a break header and footer.
    The information common to the different rows is in the "Start of break" block.
    Totals (counters, etc.) are in the "End of break" block.
    This break is used to group a set of records according to the same criterion. In our example, the break is set on the country and it is used to group all the customers living in the same country.

    Report creation wizard - Break
  12. Select "Insert breaks into the report". Go to the next step.
  13. Specify the sort item on which the break must be set. In this case, we will use several breaks:
    • the first break is set on the country.
    • the second break is set on the state.
    Uncheck the "Customer.FullName" item.
    Report creation wizard - Break
  14. Go to the next step.
  15. You are going to specify the order in which the items will be printed and how they will be distributed in the different blocks. In our example:
    • only the country will be in the "Start of break 1" block. The "Country" item is automatically associated with the "Start of break 1".
    • only the state will be in the "Start of break 2" block. The "StateProvinceRegion" item is automatically associated with the "Start of break 2".
    • only the FullName, Address, ZipCode, City, StateProvinceRegion and Country items will be displayed in the report.
    Uncheck the CustomerID, Complement, Phone, Cell and Email items.
    Report creation wizard - Items to display
    Go to the next step.
  16. This step is used to define the report layout.
    Report creation wizard - Paper format
    Keep the default values with the "Portrait" orientation.
    Print margins
    When choosing the print margins, don't forget to take into account the physical margins of the printers. The physical margins of the printers are margins where no print is allowed. Furthermore, the physical margins may be different according to the type of printer.
  17. Go to the next step.
  18. This step allows you to select the report skin template. It is recommended to use the same skin template as for the windows. In our case, select the "Phoenix" skin template and go to the next step.
  19. Finally, give a name and a title to the report and save it.
    • Enter the title: "List of customers".
    • Keep the name proposed by default: "RPT_List_of_customers".
  20. Validate.
  21. Validate in order to switch to landscape mode.
  22. Accept to reduce the report by validating.
    Report in edit mode
  23. The report is displayed in the report editor. Save the report.
The report is completed. We will now test the report to see the result.
Run the report by clicking Test element in the quick access buttons. The print destination can be:
Print mode
Select "Report viewer" and validate. The report is run and displayed in the report viewer.
Report preview
You can print the current page or the entire document by clicking the printer ("Print" tab).
To sum up
Completed project
Do you want to check the end result of the steps described here?
A completed project is available. This project contains the different windows created in this lesson. To open the completed project, go to the home page and click "Tutorial", then in "Tutorial - WINDEV application: Manage data", double-click "Full application - Answers".
In this lesson, we saw how to create reports displaying data from the database. In the next lesson, we will create a drop-down menu that allows users to print documents from the application.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 2024
Comments
Click [Add] to post a comment

Last update: 12/21/2023

Send a report | Local help