Click here to Skip to main content
15,896,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have client-server program written in c++ in visual studio, I have a function defined in that to connect to a server, read data sets, data model etc. I run the program it connects to server and it displays output on a command prompt as it is an exe . How do I send these data that are displayed on cmd prompt to a excel file using odbc or by any other means??
I am not a expert in this field. Any help thru code, link or steps would be of great help to me.
Posted

1 solution

There is an old article here: Creating Excel Sheets using ODBC[^]. It uses the MFC CDatabase class to write Excel files using ODBC.

I prefer using ADO (OLE DB) instead of ODBC. It allows passing data by values rather than by text which is especially useful with floating point values to avoid rounding errors. This does not require MFC but is more complex than using SQL commands only as with ODBC. Article: How to Read and Write Excel Files in C++ via ADO[^].

As an alternative you may create a CSV, TAB separated text, or HTML file. All these formats can be loaded by Excel.
 
Share this answer
 
Comments
Member 11553536 30-Mar-15 8:32am    
Thanks a lot for such quick reply. I will try it and if there is any question I will ask again.
Member 11553536 30-Mar-15 8:35am    
// Insert data
sSql = "INSERT INTO demo (Name,Age) VALUES ('Bruno Brutalinsky',45)";
database.ExecuteSQL(sSql);

sSql = "INSERT INTO demo (Name,Age) VALUES ('Fritz Pappenheimer',30)";
database.ExecuteSQL(sSql);

sSql = "INSERT INTO demo (Name,Age) VALUES ('Hella Wahnsinn',28)";
database.ExecuteSQL(sSql);


In this part of the code , we are feeding the data. I want to this data to be fed directly from the data sent by server. I am not sure if I am clear with my question .
Jochen Arndt 30-Mar-15 8:42am    
What I understand:
You have a client program that receives data from a server and prints the data to the console. Now you want to write the data to an Excel file.

If that is not what you want, you should refine your question.
Member 11553536 30-Mar-15 8:46am    
Exactly that's my question. But in the above commands we are not taking the data from server , we are writing it manually, isn't it??
Jochen Arndt 30-Mar-15 8:56am    
I don't see the problem. Before you can write data, you must get them from the server. You are actually printing the data to the console. So just replace that with writing to file (or perform both operations).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900