Thread: Writing output to separate columns of same excel spreadsheet. Overlaying charts.

  1. #1
    Registered User
    Join Date
    Sep 2010
    Location
    London
    Posts
    41

    Writing output to separate columns of same excel spreadsheet. Overlaying charts.

    Hello,

    2Qns please:

    1. Does anybody know please how can I write output to excel file, but to populate 2 columns? Currently this code puts everything into one collumn:

    Code:
    ofstream ouputFile("data.xls");
    int MSE = 5;
    int percent = 25;
    outputFile << MSE << percent << endl;
    I need the 'MSE' to go into first column in excel and 'percent' to go into second column.
    The reason is I will output many data for each and then will plot them.

    2. On this note: (pure Excel question)
    Does anybody know how to overlay 2 charts in Excel? I will be plotting financial market data on one chart (high, low, open, close) and then would like to add to the same chart another plot of my predicted high, low, open, close (all data is in excel spreadsheet). This will allow me to look at the actual market data vs my predictions, ie making it easier to see how well the prediciton coincides with the real thing.

    Thank you very much!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    True excel files are not printable text.

    What you can generate easily though is a CSV file, which excel will readily import.
    Code:
    ofstream ouputFile("data.csv");
    int MSE = 5;
    int percent = 25;
    outputFile << MSE << "," << percent << endl;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Please note that while csv means comma separated values in some regions it may actually be a semicolon m-(
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Location
    London
    Posts
    41
    Dough lol I did try that but kept writing to excel so it obviously it didnt work!
    OK great thank you for your help This is working fine now.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Location
    London
    Posts
    41
    Any ideas on overlaying the charts in Excel at all please? Still haven't been able to find out how to do it..

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Your best way to do this in C++ is using COM - not easy even with COM library help from MFC or ATL

  7. #7
    Registered User
    Join Date
    Sep 2010
    Location
    London
    Posts
    41
    Sorry I mean just as a straight Excel question..

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    More than a little off topic for this board, but if you include your actual data as well as predictions in your pivot-table you can add the extra data as a value in your chart but format it as another type of chart (IE line chart against a bar chart). Kind of like attached

  9. #9
    Registered User
    Join Date
    Sep 2010
    Location
    London
    Posts
    41
    Why is the Final weight Table1 wrtten all in 1 column for everything in the 2nd loop, but final weight talbe 2 is separated into columns per weight (as needed)??? Am puzzled! Code is the same why doesn't it do it for both?

    Code:
    weightsFile << "Final weights for talbe 1 are: " << endl;
    			for(int i=0; i<n; i++)						// for each row
    			{
    				for(int j=0; j<x; j++)					// for each element in the row
    					weightsFile << finalWeightTable1[i][j] << ",";
    				weightsFile << endl;
    			}
    
    			weightsFile << "Final weights for table 2 are:" << endl;
    			for(int i=0; i<y; i++)
    			{
    				for(int j=0; j<n; j++)
    					weightsFile << finalWeightTable2[i][j] << ",";
    				weightsFile << endl;
    			}

  10. #10
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Try posting the actual output and check values for x and y

  11. #11
    Registered User
    Join Date
    Sep 2010
    Location
    London
    Posts
    41
    Sorry I don't understand what you mean? You'd like me to post what this code writes to Excel?
    Last edited by Kat007; 09-24-2010 at 01:23 PM.

  12. #12
    Registered User
    Join Date
    Sep 2010
    Location
    London
    Posts
    41
    @Fordy, I have high low open and close for financial data and need to overlay 4 data with another 4 data for a few hundred lines. I have attached an example. Rather than having the 2 charts Id like to have them on 1!..... Please help if you know how, need to present my dissertation in a nice format!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IDE for C embedded advanced editing
    By Undici77 in forum Tech Board
    Replies: 32
    Last Post: 01-16-2010, 05:17 PM
  2. Problems installing Mingw5.1.4
    By BlackOps in forum C Programming
    Replies: 2
    Last Post: 07-26-2009, 03:28 AM
  3. Replies: 1
    Last Post: 05-05-2006, 11:17 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM

Tags for this Thread