Do not let any software impress you!

Only let it convince your intellect.
Slider img 1
Do not look for a business paradise!

It is a waste of time.
Slider img 2
Only yourself can push you uphill.

There is no easy road to prizes.
Slider img 3
Productivity is the name of the game.

And you have to conquer it.
Slider img 4
As long as you understand it,

you will start to build your know-how.
Slider img 5
We can help with that.

We have the tools and the method.
Slider img 6

Export data to Ms Excel



It’s often necessary to convert data stored in your database to another form, such as an Excel workbook. For example, you may wish to take advantage of Excel’s unique analytical capabilities or share data with someone unfamiliar with databases. Whatever the reason, the conversion process is pretty straightforward and quick.
To export data from your database to Excel, you must create a script file (*.cd).
In the file, you must have the query that will call the data from the tables you want and the commands to export the data to Excel.
Let’s take a few moments to walk through the process step-by-step.

1. Open the application.
2. Right-click and select “Developer.”
3. Select “Scripts” and then select “Create.”
4. In the window, you must write your code. The example below shows the code for exporting three columns, customer name, address, and phone, from the table customer.

proc exp_customer()

       start_sql “CUSTOMER” “KOSMOS”
         SELECT
         CUSTOMER.FIRST_NAME, CUSTOMER.LAST_NAME,
         CUSTOMER.ADDRESS, CUSTOMER.PHONE
         FROM
         CUSTOMER
         ORDER BY
         CUSTOMER.LAST_NAME, CUSTOMER.FIRST_NAME
       end_sql

       call RunEmbSQL(“CUSTOMER”)

       q = QueryByName(“CUSTOMER”)
       rcount = TRecordCount(q)
 
       call DisconnectExcel() this command closes ms excel

       call OpenExcelDoc(“C:\CUSTOMER.XLS”) this command opens the excel file (we must create this file, the data always exports into an existing excel file)

       call SetExCell2(“A1”;” CUSTOMERS”;ftString). This command puts the value CUSTOMERS in A1 cell.

       line = 0
      
       call TFirst(q)
       for i = 1 to rcount

         name = strcat(CUSTOMER.LAST_NAME;” “;CUSTOMER.FIRST_NAME)

         line = line + 1

         call SetExCell1(line;2;name;ftString)
         call SetExCell1(line;3;DATA.ADDRESS;ftString)
         { this command puts the field address in C1 cell, the first parameter is the line,}
         { the second is the column, the third is the value you want to put in the cell, }
         { the fourth it the type of the value, ftString for strings and ftFloat for numbers }
         call SetExCell1(line;4;DATA.PHONE;ftString)

         call TNext(q)
       next

       call FreeEmbSQL(“CUSTOMER”)

       call ShowExcel() this command opens the excel and the file

end

5. Save changes and close the window.
6. Call the procedure.
(You can call the procedure from the menu or with a button.
The command you use is “call procedure name().”
For example “call exp_customer()“ )