Like Tree2Likes
  • 1 Post By Swarvy
  • 1 Post By Fordy

Outputting Data to Excel Sheet - MFC Application

This is a discussion on Outputting Data to Excel Sheet - MFC Application within the C++ Programming forums, part of the General Programming Boards category; Hi, I have read some of the topics that were posted on a similar topic to mine but would like ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    223

    Question Outputting Data to Excel Sheet - MFC Application

    Hi,



    I have read some of the topics that were posted on a similar topic to mine but would like some specific guidance please.



    I have a simulation developed in C++ on VS 2010. Currently, the program produces multiple text file outputs containing data. Each seperate file represents different conditions. There could be anything from 1 to 100 of these text files outputted depending upon how I set it up.



    What I normally do, is after I have run the program I gather the data manually in to an excel workbook to analyse the data. This involves importing the data from a text file using 'Fixed Width' setting whereby the fields are arranged in columns with spaces between each field. Each text file contains 2 columns of data.



    What I want: is to write all the data (not only to the text files) but also to the same excel worksheet. This will save me a lot of time, not having to manually import each text files data using the Excel import feature.

    For each set of data I would require one cell to have a description (kind of like a title to describe the data) and then underneath the 2 columns of data which would have multiple row entries. One blank column space between each different test set would be ideal to make it easier to distinguish them. e.g.) Cell A1 - Description; Cell A2:A26 and B2:B26 would contain data. Column C cells would be blank. Cell D1 - Description; Cell D226 and E2:E26 would contain data. Column F cells would be blank. etc. etc.



    The thing is, I have never done anything like this before and I wouldn't know how to or where to begin. Like I said, my code is developed using MFC in C++. If you can provide any ideas or point me in the right direction I would be most grateful?



    Thanks!!!

  2. #2
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    I don't know about the specifics of the MS excel file format but you could just write everything you need in a CSV file and excel should be able to open it as you want. It is quite easy to write data in CSV format since there is no metadata in the file format. There are some potential disadvantages to this method though (e.g. giving each cell a description, I don't know if you can get away with that using this CSV idea).

    Just a thought.

    Another idea is to look around for library which allows you to write in the excel's format (saves you a whole load of work).
    Last edited by Swarvy; 06-27-2011 at 06:53 AM.
    strokebow likes this.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    223
    Thanks for your suggestion.

    I can see the merit in that. Maybe I could include the description in the first entry of the first column. That would probably work.

    So, if I am able to save all the data to 1 CSV file. You think that if I can then just import the one CSV file into excel?? Its not strictly what I wanted to do. But if it gets the job done and its easy then it could be the way forward

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Its the best option, IMHO.

    The other ways are to use COM or understand the raw file format. The later is a little easier with the new file formats (.xlsx) but its still a hell of a lot of work for what its worth. That's why almost every app that exports tabular data that can be used in excel does so via CSV first...then they may offer other formats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 41
    Last Post: 12-16-2010, 09:17 PM
  2. Outputting to excel...
    By osiris^ in forum C Programming
    Replies: 2
    Last Post: 09-27-2008, 08:21 AM
  3. How to access excel sheet with C program(open,read,write)
    By jaininaveen in forum C Programming
    Replies: 4
    Last Post: 01-29-2006, 10:17 AM
  4. Replies: 1
    Last Post: 10-22-2005, 05:28 AM
  5. Replies: 0
    Last Post: 01-24-2005, 06:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21