How to merge several csv files into one

2017-08-29

This article aims to provide the insight into how to use FastReport.Net to merge two logically related CSV files into one.  Storing data in CSV files is often very convenient. You can always open such files by any text editor and tweak them. But what if in one document there are references to data from the other document? You have to merge two files into one, for further convenient work with the CSV document. It can be done manually, which is rather time - consuming, or you can use Excel, that requires some knowledge of the macros. The third way is the most easy-to-handle - to use FastReport.

So, we have two CSV files. One contains a list of orders, the second one - a list of customers. We need to display the customers' names and phone numbers for each order. The Orders table has a foreign key "CustNo' to the Customers table. In turn, the Customers table has the primary "CustNo" key. As you understand, we will link the two tables to this field.

Create a new report in the designer. Add a new data source -  a CSV file:

One more data source is the second file.

As a result, we get two connections:

 

Now we need to link two tables. To do this, click the drop-down menu "Actions" and select "New relation".

 

We select the main table, for example "Orders". The subordinate table is "Customers". For both tables we define the key fields. In our case, in both tables the keys are called "CustNo":

 

Now look at the window "Data":

 

For the Customers table now there is an associated table "Orders".

We place the Company field in the Customers table on the Data band. We also place all fields there, except the CustNo fields, which are from the linked table " Orders". As there are a lot of fields, they do not fit on the report page. Open the page settings in the top toolbar "Report":

 

On the "Other" tab we set properties: Extra design width, unlimited height, unlimited width. The last two properties allow you to expand your report page to the required size in the report view mode.

Before exporting the report to a CSV file, let us consider some useful tips on formatting. To prevent the addition of blank lines and columns in the export, try to place the margins on your page close to each other. For the header of the data, we reduce the height to a minimum:

Now run the report in preview mode.

 

Click "Save" and choose "CSV file...". Now agree with the default export settings and set the location of the file saving. As a result, we have a CSV file with information about orders and the company name instead of the CustNo identifier.

 

Using the introduced way, you can merge as many tables as you need from different CSV files, which is really time - saving. Creation of a merged file takes about 10 minutes.

.NET .NET FastReport FastReport Desktop Desktop CSV CSV
April 22, 2025

Working with the TfrShellTreeView Component in FastReport VCL

In this article, we will look at the TfrShellTreeView component. It is designed to display file system elements and is partially analogous to the TDirectoryListBox, TDirectoryOutline, and TShellTreeView components.
April 21, 2025

How RFID Tags Work in FastReport VCL

In this article, we'll check out how RFID tags work with the new TfrxDeviceCommand object in FastReport VCL with release 2025.2.
April 08, 2025

How to Set Up a Connection to Apache Ignite in FastReport .NET

In this article, we will explore how to configure a connection to Apache Ignite in FastReport .NET. You will learn the necessary steps to connect the plugin via code and the report designer.
Fast Reports
  • 800-985-8986 (English, US)
  • +31 97 01025-8466 (English, EU)
  • +49 30 56837-3928 (German, DE)
  • +55 19 98147-8148 (Portuguese, BR)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2025 Fast Reports Inc.