Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C++ question

C++ question

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajveer
    wrote on last edited by
    #1

    This is just a C++ question. Does anybody know how to get data from an excel file? I figured out a way to put data to an excel file. I just do this: ofstream outfile("ftest.out"); int a=1, b=2, c=3, d=4; outfile << a << "," << b << "," << c << "," << d; then when I open ftest.out with excel, it recognizes that the comma means to move to the next block. But when I try to get data from an excel file the same way: ifstream infile("ftest.in"); int a, b, c, d; infile >> a >> "," >> b >> "," >> c >> "," >> d; This doesn't work. Does anyone know some other method to get data from an excel file?

    J R M N 4 Replies Last reply
    0
    • R Rajveer

      This is just a C++ question. Does anybody know how to get data from an excel file? I figured out a way to put data to an excel file. I just do this: ofstream outfile("ftest.out"); int a=1, b=2, c=3, d=4; outfile << a << "," << b << "," << c << "," << d; then when I open ftest.out with excel, it recognizes that the comma means to move to the next block. But when I try to get data from an excel file the same way: ifstream infile("ftest.in"); int a, b, c, d; infile >> a >> "," >> b >> "," >> c >> "," >> d; This doesn't work. Does anyone know some other method to get data from an excel file?

      J Offline
      J Offline
      Jack Handy
      wrote on last edited by
      #2

      I don't know how to get the data from a normal excel file but I do know why your outfile code worked and your infile code doesn't... Your ftest.out file would be considered a csv file (comma seperated values) and excel supports csv. A normal excel file is not stored in csv format. Sorry I don't really have an answer but at least you know it isn't some little bug in your code. There are a few articles here on codeproject dealing with excel files, maybe you could find an answer there... try here for instance -Jack To an optimist the glass is half full. To a pessimist the glass is half empty. To a programmer the glass is twice as big as it needs to be.

      1 Reply Last reply
      0
      • R Rajveer

        This is just a C++ question. Does anybody know how to get data from an excel file? I figured out a way to put data to an excel file. I just do this: ofstream outfile("ftest.out"); int a=1, b=2, c=3, d=4; outfile << a << "," << b << "," << c << "," << d; then when I open ftest.out with excel, it recognizes that the comma means to move to the next block. But when I try to get data from an excel file the same way: ifstream infile("ftest.in"); int a, b, c, d; infile >> a >> "," >> b >> "," >> c >> "," >> d; This doesn't work. Does anyone know some other method to get data from an excel file?

        R Offline
        R Offline
        Roger Wright
        wrote on last edited by
        #3

        I haven't tried it, but generally, if you export the Excel file in ASCII or .csv format (whichever it offers you as an option) the result will be a comma-separated text file. You can then read it as char data and parse the fields using the commas as end-of-field indicators. I believe there's a tokenizer function that does this, but I'm far from my MSDN library right now. Check there online for "token" or some such.

        R 1 Reply Last reply
        0
        • R Rajveer

          This is just a C++ question. Does anybody know how to get data from an excel file? I figured out a way to put data to an excel file. I just do this: ofstream outfile("ftest.out"); int a=1, b=2, c=3, d=4; outfile << a << "," << b << "," << c << "," << d; then when I open ftest.out with excel, it recognizes that the comma means to move to the next block. But when I try to get data from an excel file the same way: ifstream infile("ftest.in"); int a, b, c, d; infile >> a >> "," >> b >> "," >> c >> "," >> d; This doesn't work. Does anyone know some other method to get data from an excel file?

          M Offline
          M Offline
          Michael A Barnhart
          wrote on last edited by
          #4

          There is (was) an "Excel Developers Kit" (book) that at least went through the 97 version. Good ideas are not adopted automatically. They must be driven into practice with courageous patients. -Admiral Rickover. ...

          1 Reply Last reply
          0
          • R Rajveer

            This is just a C++ question. Does anybody know how to get data from an excel file? I figured out a way to put data to an excel file. I just do this: ofstream outfile("ftest.out"); int a=1, b=2, c=3, d=4; outfile << a << "," << b << "," << c << "," << d; then when I open ftest.out with excel, it recognizes that the comma means to move to the next block. But when I try to get data from an excel file the same way: ifstream infile("ftest.in"); int a, b, c, d; infile >> a >> "," >> b >> "," >> c >> "," >> d; This doesn't work. Does anyone know some other method to get data from an excel file?

            N Offline
            N Offline
            Nick Parker
            wrote on last edited by
            #5

            You may consider using the getline method:

            ifstream infile("ftest.in");
            char[81] myText;
            for(int i = 0;!infile.eof;i++)
            {
            myText = infile.getline(myText);

            }

            Hope something like this helps. Nick Parker

            1 Reply Last reply
            0
            • R Roger Wright

              I haven't tried it, but generally, if you export the Excel file in ASCII or .csv format (whichever it offers you as an option) the result will be a comma-separated text file. You can then read it as char data and parse the fields using the commas as end-of-field indicators. I believe there's a tokenizer function that does this, but I'm far from my MSDN library right now. Check there online for "token" or some such.

              R Offline
              R Offline
              Rajveer
              wrote on last edited by
              #6

              How do I export the Excel file in ASCII or .csv format? Do you mean that this is an option in the excel program itself, or do you mean that visual C++ has the ability to do this to the file? If its an option in excel itself, could you tell me how to go about exporting the file?

              R 1 Reply Last reply
              0
              • R Rajveer

                How do I export the Excel file in ASCII or .csv format? Do you mean that this is an option in the excel program itself, or do you mean that visual C++ has the ability to do this to the file? If its an option in excel itself, could you tell me how to go about exporting the file?

                R Offline
                R Offline
                Roger Wright
                wrote on last edited by
                #7

                I don't use Excel, though several at work do, so I'm not certain how to do it. But I believe I found it once in the File menu. Check there for an Export option; it should offer you a set of format selections, including text (aka ASCII, or CSV). If it's not there, check the online Help for "Exporting." Every other spreadsheet program since Calc has had this option, so I doubrt that it's been left out. A potential problem might come up when using multiple sheet spreadsheets - it may export only one sheet - you'll need to manually review the resulting file to see what you've got.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups