How to create CSV file from Active Report 6

A common requirement is to have applications share data with other programs. Although there are interfaces available to work with, for example, CSV files. A much simpler way to have your application share data is by reading and writing Comma-Separated Values (CSV) files. CSV files can easily be read and written by many programs, including Microsoft Excel.

Active Report 6 developers sometime needs to export report data to CSV file. Now we describe how to do it. We have Order Details Report. Supose we have some text fields into Details section and need to export the whole report data into a new CSV file named “OrderDetails.csv”. We use Active Report 6 with C# language support.

The “Orders.xml” file structure is:

<?xml version=”1.0″ encoding=”utf-8″?>
<Orders>
   <Order ID=”10248″>
 <Product>
     <Description>Queso Cabrales</Description>
     <Discount>0%</Discount>
     <UnitPrice>$14.00</UnitPrice>
     <Quantity>12</Quantity>
     <ExtendedPrice>$168.00</ExtendedPrice>
        </Product>
 <Product>
     <Description>Singaporean Hokkien Fried Mee</Description>
     <Discount>0%</Discount>
     <UnitPrice>$9.80</UnitPrice>
     <Quantity>10</Quantity>
     <ExtendedPrice>$98.00</ExtendedPrice>
        </Product>
 <Product>
     <Description>Mozzaralla of Giovanni</Description>
     <Discount>0%</Discount>
     <UnitPrice>$34.80</UnitPrice>
     <Quantity>5</Quantity>
     <ExtendedPrice>$174.00</ExtendedPrice>
        </Product>
   </Order>
   <Order ID=”10249″>
 <Product>
     <Description>Manjimup Dried Apples</Description>
     <Discount>0%</Discount>
     <UnitPrice>$42.40</UnitPrice>
     <Quantity>40</Quantity>
     <ExtendedPrice>$1696.00</ExtendedPrice>
        </Product>
 <Product>
     <Description>Tofu</Description>
     <Discount>0%</Discount>
     <UnitPrice>$18.60</UnitPrice>
     <Quantity>9</Quantity>
     <ExtendedPrice>$167.40</ExtendedPrice>
        </Product>
   </Order>
   <Order ID=”10250″>
 <Product>
     <Description>Manjimup Dried Apples</Description>
     <Discount>15%</Discount>
     <UnitPrice>$42.40</UnitPrice>
     <Quantity>35</Quantity>
     <ExtendedPrice>$1261.40</ExtendedPrice>
        </Product>
 <Product>
     <Description>Jack’sNewEnglandClean Chowder</Description>
     <Discount>0%</Discount>
     <UnitPrice>$7.70</UnitPrice>
     <Quantity>10</Quantity>
     <ExtendedPrice>$77.00</ExtendedPrice>
        </Product>
 <Product>
     <Description>Louisiana Fiery Hot Perrer Sauce</Description>
     <Discount>15%</Discount>
     <UnitPrice>$16.80</UnitPrice>
     <Quantity>15</Quantity>
     <ExtendedPrice>$214.20</ExtendedPrice>
        </Product>
   </Order>
   <Order ID=”10251″>
 <Product>
     <Description>Louisiana Fiery Hot Perrer Sauce</Description>
     <Discount>0%</Discount>
     <UnitPrice>$16.80</UnitPrice>
     <Quantity>20</Quantity>
     <ExtendedPrice>$336.00</ExtendedPrice>
        </Product>
 <Product>
     <Description>Gustafs Knackebrod</Description>
     <Discount>5%</Discount>
     <UnitPrice>$16.80</UnitPrice>
     <Quantity>6</Quantity>
     <ExtendedPrice>$95.70</ExtendedPrice>
        </Product>
 <Product>
     <Description>Ravidi Angelo</Description>
     <Discount>5%</Discount>
     <UnitPrice>$15.60</UnitPrice>
     <Quantity>15</Quantity>
     <ExtendedPrice>$222.30</ExtendedPrice>
        </Product>
   </Order>
   <Order ID=”10252″>
 <Product>
     <Description>Getost</Description>
     <Discount>5%</Discount>
     <UnitPrice>$2.00</UnitPrice>
     <Quantity>25</Quantity>
     <ExtendedPrice>$47.50</ExtendedPrice>
        </Product>
   </Order>
</Orders>

The report looks like:

OrderDetailsReport

To create csv file we have to implements the given steps:

1. Add the following line into class scope of the report:


using System.IO;

2. We add code into detail section of the report:

public void Detail_Format()
{
 //csv file OrderDetails
 string columnText = “”;
 string columnHeaderText = “”;
 //Header Text
 columnHeaderText = “Order ID” + ‘,’ + “Product” + ‘,’ + “Discount” + ‘,’ + “Unit Price” + ‘,’ + “Quantity” + ‘,’ + “Extended Price”;
 
 columnText = fldOrderId.Text + ‘,’ + fldProductDescription.Text + ‘,’ + fldDiscount.Text + ‘,’ + fldUnitPrice.Text + ‘,’ + fldQuantity.Text + ‘,’ + fldExtendedPrice.Text;


 string filename = “OrderDetails.csv”;
 StreamWriter sw = new StreamWriter(filename, true);
 //add Header to CSV
 if(bAddHeader == false)
 {
  sw.WriteLine(columnHeaderText);
  bAddHeader = true;
 }
 else
 {
  //Add order details
  sw.WriteLine(columnText);
 }
 sw.Close();
}

Now run the report or click on the “Preview” tab to view reports output. The “OrderDetails.csv” file is created into the application directory. The output file is looks like below:

 You can download source files from here

How can you develop reports with Active Report 6

Active Report 6 is a reporting tool for Silverlight, Windows forms and ASP.NET that will help you to make reports easier and faster.  It gives newbies the confidance they need to create simple reports without spending unproductive, ramp-up hours. ActiveReports leverages the latest technologies including ActiveX, XML, ActiveScripting and CSS to provide you with full integration, open architecture, and a user-friendly interface. These include upgrade tools, MS Access and other report converters, the Visual Studio report designer, the end-user report designer, charts, bar codes, export plug-ins and the .NET reporting SDK. The “End user designer” allows end users to edit reports, save and load report layouts. It allows you to monitor and control the design environment and customize the report’s look and feel to meet the needs of your end users. 

Installation:

  • Select RUN from the Windows Start Menu.
  • Type <setup file path>\SETUP.EXE.
  • Click OK or press Enter to run the installation program.
  • When prompted, enter your name, organization and serial number.
  • Read the license agreement.
  • Select your installation directory or accept the suggested default directory.
  • Select the directory for the dll and ocx installation or accept the suggested default.
  • Select the components you wish to install.
  • Type the name of the program group or keep the default value.
  • Click Next to proceed with the installation.
  • The installation program copies all of the selected ActiveReports components to the specified directory and registers the control and DLLs in your system registry.
  • You are now ready to use ActiveReports 2.

You also use End user designer  which required some dll files and exe file will need to be placed under the same folder.

ActiveReports.Chart.dll, ActiveReports.CodeDomSerializer6.dll, ActiveReports.Design6.dll, ActiveReports.Document.dll, ActiveReports.Interop.dll,
ActiveReports.Viewer6.dll, ActiveReports6.dll and EndUserDesigner.exe files. Double click the End user designer.exe file. The following Interface will open:

1. This is the list of controls available to the report design.

2. This is page header section which is displayed at the beginning of each report page. You can also add Report Section and Group sections. The Report section is displayed once at the beginning of the report. The Group sections are the ones used to regroup details as separate lists.

3. The Detail section corresponds to the position of the recordset pattern specified in the OLEDB, SQLDB or XML Data Source of the report.

4. This tab represents the code that the current RPX report design can execute. You can use VB script or C# script, set in the properties list of the report.

5. The Preview tab display the report output view.

6. This is the data information.  It gives the possibilities to add directly fields to the report (2-3) designer.  It gives also the access to the report general settings.

7.  List of all the available properties of the current selection.

Now I describe how we design a new report using XML file as datasource.  We use Inventory.xml file as datasource to design the sample report.

* Launch the End-User-Designer and click on the ‘File’ menu and select the New option or the ‘New’ icon from the toolbar.   

* Set the datasource: Select the Report node in the upper right control panel of the End-User Designer. This selection will assign the report properties of the report. Just below this list of properties, you will have access to a new link ‘Edit Data Source’.


Click on the link will prompt a dialog with datasource information as follows:

Now by clicking on the ‘Report’ on upper right box you can see ‘Field’ node. While expanding the node with click on the + sign you can access all required fields which you use to design the report. Just drag and drop the field into report section and click ‘Preview’ tab. You can see the report data.  All the Group sections can have an Xml Path assign to indicate at which data change they need to be displayed.  This Xml pattern can be found in the section property named “DataField”.

You have to set the report path from which the main report will get all sub reports to display. Take a textbox from toolbar and named it as ‘RptPath’. Now into its text property enter your report folder path like – “D:\WorkArea\Reports\Items”. Save the file as ‘MainItems.rpx’.

There are mandatory fields or values that need to be set for the report.  we discuss it later.