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. save data as csv or excel

save data as csv or excel

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
12 Posts 6 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.
  • V viperlogic

    im using VC++6 MFC, i want to create and save some data out to a file such as a csv file or even better a excel file. I know of CFileDialog to bring up a save dialog but how do i pump out data in a csv or excel format thanks

    V Offline
    V Offline
    venadder
    wrote on last edited by
    #2

    have your data as comma seperated values each row seperated by newline adn then jsut give the file .csv extension. That's how I used to do it.

    V 1 Reply Last reply
    0
    • V venadder

      have your data as comma seperated values each row seperated by newline adn then jsut give the file .csv extension. That's how I used to do it.

      V Offline
      V Offline
      viperlogic
      wrote on last edited by
      #3

      how did you write the data out thou, i see there is CArchive but doesnt appear to do much!!

      J 1 Reply Last reply
      0
      • V viperlogic

        im using VC++6 MFC, i want to create and save some data out to a file such as a csv file or even better a excel file. I know of CFileDialog to bring up a save dialog but how do i pump out data in a csv or excel format thanks

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #4

        viperlogic wrote:

        im using VC++6 MFC, i want to create and save some data out to a file such as a csv file or even better a excel file.

        To communicate with Excel, you can use its ODBC driver, or Excel automation.

        viperlogic wrote:

        I know of CFileDialog to bring up a save dialog...

        CFileDialog has nothing to do with how the data is saved. It is for filename selection only.


        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

        "There is no death, only a change of worlds." - Native American Proverb

        1 Reply Last reply
        0
        • V viperlogic

          im using VC++6 MFC, i want to create and save some data out to a file such as a csv file or even better a excel file. I know of CFileDialog to bring up a save dialog but how do i pump out data in a csv or excel format thanks

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #5

          [Message Deleted]

          V 1 Reply Last reply
          0
          • V viperlogic

            how did you write the data out thou, i see there is CArchive but doesnt appear to do much!!

            J Offline
            J Offline
            Justin Tay
            wrote on last edited by
            #6

            There must be at least dozen ways to write a file. I suppose if you want something MFC there is CFile or CStdioFile? Perhaps even this http://www.codeproject.com/file/stdiofileex.asp#xx1295590xx[^] if you want some unicode support.

            1 Reply Last reply
            0
            • L Lost User

              [Message Deleted]

              V Offline
              V Offline
              viperlogic
              wrote on last edited by
              #7

              im wanna go down the csv route. i am using the CArchive as follows CFile f; char strFilter[] = { "csv Files (*.csv)|*.csv|All Files (*.*)|*.*||" }; CFileDialog FileDlg(FALSE, ".csv", NULL, 0, strFilter); if( FileDlg.DoModal() == IDOK ) { f.Open(FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite); CArchive ar(&f, CArchive::store); ar<< m_Make << m_Model << m_Year << m_Mileage << m_Owner; ar.Close(); } else return; f.Close(); the above is coming out in one cell with a rectangular box after each string how do i get ride of those retangular boxes and have a string in a seperate cell thanks

              D 1 Reply Last reply
              0
              • V viperlogic

                im wanna go down the csv route. i am using the CArchive as follows CFile f; char strFilter[] = { "csv Files (*.csv)|*.csv|All Files (*.*)|*.*||" }; CFileDialog FileDlg(FALSE, ".csv", NULL, 0, strFilter); if( FileDlg.DoModal() == IDOK ) { f.Open(FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite); CArchive ar(&f, CArchive::store); ar<< m_Make << m_Model << m_Year << m_Mileage << m_Owner; ar.Close(); } else return; f.Close(); the above is coming out in one cell with a rectangular box after each string how do i get ride of those retangular boxes and have a string in a seperate cell thanks

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #8

                viperlogic wrote:

                the above is coming out in one cell

                But what does it look like when viewed with Notepad? Try:

                CStdioFile f;
                ...
                ar << m_Make << ',' << m_Model << ',' << m_Year << ',' << m_Mileage << ',' << m_Owner << endl;


                "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                "There is no death, only a change of worlds." - Native American Proverb

                V 1 Reply Last reply
                0
                • D David Crow

                  viperlogic wrote:

                  the above is coming out in one cell

                  But what does it look like when viewed with Notepad? Try:

                  CStdioFile f;
                  ...
                  ar << m_Make << ',' << m_Model << ',' << m_Year << ',' << m_Mileage << ',' << m_Owner << endl;


                  "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                  "There is no death, only a change of worlds." - Native American Proverb

                  V Offline
                  V Offline
                  viperlogic
                  wrote on last edited by
                  #9

                  still get the boxes as seen below a,b,c,d,e

                  D 1 Reply Last reply
                  0
                  • V viperlogic

                    still get the boxes as seen below a,b,c,d,e

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #10

                    Which implies that m_Make, m_Model, m_Year, m_Mileage, and m_Owner have an odd character in them. Yes?


                    "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                    "There is no death, only a change of worlds." - Native American Proverb

                    V 1 Reply Last reply
                    0
                    • D David Crow

                      Which implies that m_Make, m_Model, m_Year, m_Mileage, and m_Owner have an odd character in them. Yes?


                      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                      "There is no death, only a change of worlds." - Native American Proverb

                      V Offline
                      V Offline
                      viperlogic
                      wrote on last edited by
                      #11

                      CString m_Make="a"; CString m_Model ="b"; CString m_Year ="c"; CString m_Mileage ="d"; CString m_Owner="e"; for testing purposes i have them as above, so where is this box coming from!!!

                      J 1 Reply Last reply
                      0
                      • V viperlogic

                        CString m_Make="a"; CString m_Model ="b"; CString m_Year ="c"; CString m_Mileage ="d"; CString m_Owner="e"; for testing purposes i have them as above, so where is this box coming from!!!

                        J Offline
                        J Offline
                        jhwurmbach
                        wrote on last edited by
                        #12

                        viperlogic wrote:

                        so where is this box coming from!!!

                        Unicodedness of your program without writing the unicode-header? A decent file editor (as opposed to a CEdit-gone-application like notepad) like Ultraedit would show it.


                        "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

                        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