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. Need to create Document and Excel in vc++

Need to create Document and Excel in vc++

Scheduled Pinned Locked Moved C / C++ / MFC
c++comhelp
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.
  • H Offline
    H Offline
    harinath
    wrote on last edited by
    #1

    Hi, I want to create word document and excel documents through vc++ programs for dynamic data that i get from some data base. I am just beginning, Any body who knows this please do help me. cheers harinath Harinath Reddy HOneywell Technology Solutions Lab, Bangalore, India-560076 harinath@vandemataram.com

    D D 2 Replies Last reply
    0
    • H harinath

      Hi, I want to create word document and excel documents through vc++ programs for dynamic data that i get from some data base. I am just beginning, Any body who knows this please do help me. cheers harinath Harinath Reddy HOneywell Technology Solutions Lab, Bangalore, India-560076 harinath@vandemataram.com

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

      Use OLE Automation. Here's an Excel example:

      \_Application    app;
      Workbooks       books;
      \_Workbook       book;
      Worksheets      sheets;
      \_Worksheet      sheet;
      Range           range;
      COleVariant     vtOptional((long) DISP\_E\_PARAMNOTFOUND, VT\_ERROR),
                      vtTrue((short) TRUE),
                      vtFalse((short) FALSE);
      CString         strText;
      
      
      if (app.CreateDispatch("Excel.Application") == TRUE)
      {
          app.SetVisible(TRUE);
      
          books = app.GetWorkbooks();
      
          book = books.Add(vtOptional);
      
          sheets = book.GetSheets();
      
          sheet = sheets.GetItem(COleVariant((short) 1));
      
          range = sheet.GetRange(COleVariant("A1"), COleVariant("A1"));
          m\_ebCellA1.GetWindowText(strText);
          range.SetValue(COleVariant(strText));
          
          range = sheet.GetRange(COleVariant("A2"), COleVariant("A2"));
          m\_ebCellA2.GetWindowText(strText);
          range.SetValue(COleVariant(strText));
      
          range = sheet.GetRange(COleVariant("A4"), COleVariant("A4"));
          range.SetFormula(COleVariant("=A1 + A2"));
      }
      

      Here's a Word example:

      CString         strFileName;
      \_Application    app;
      Documents       docs;
      \_Document       doc;
      COleVariant     vtOptional((long) DISP\_E\_PARAMNOTFOUND, VT\_ERROR), 
                      vtFalse((short) FALSE),
                      vtTrue((short) TRUE);
      
      
      if (app.CreateDispatch("Word.Application") == TRUE)
      {
          docs = app.GetDocuments();
      
          m\_ebDocName.GetWindowText(strFileName);
      
          doc = docs.Open(COleVariant(strFileName), vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional);
      
          doc.PrintOut(vtFalse, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional);
      
          while (app.GetBackgroundPrintingStatus() > 0)
              ;
      
          docs.Close(vtFalse, vtOptional, vtOptional);
      
          app.Quit(vtOptional, vtOptional, vtOptional);
      }
      
      A 1 Reply Last reply
      0
      • H harinath

        Hi, I want to create word document and excel documents through vc++ programs for dynamic data that i get from some data base. I am just beginning, Any body who knows this please do help me. cheers harinath Harinath Reddy HOneywell Technology Solutions Lab, Bangalore, India-560076 harinath@vandemataram.com

        D Offline
        D Offline
        Dimitris Vasiliadis
        wrote on last edited by
        #3

        You could use ODBC and treat EXCEL sheets like tables. Take a look at: http://www.codeproject.com/database/excel_odbc_write.asp http://www.codeproject.com/database/excel_odbc.asp

        H 1 Reply Last reply
        0
        • D David Crow

          Use OLE Automation. Here's an Excel example:

          \_Application    app;
          Workbooks       books;
          \_Workbook       book;
          Worksheets      sheets;
          \_Worksheet      sheet;
          Range           range;
          COleVariant     vtOptional((long) DISP\_E\_PARAMNOTFOUND, VT\_ERROR),
                          vtTrue((short) TRUE),
                          vtFalse((short) FALSE);
          CString         strText;
          
          
          if (app.CreateDispatch("Excel.Application") == TRUE)
          {
              app.SetVisible(TRUE);
          
              books = app.GetWorkbooks();
          
              book = books.Add(vtOptional);
          
              sheets = book.GetSheets();
          
              sheet = sheets.GetItem(COleVariant((short) 1));
          
              range = sheet.GetRange(COleVariant("A1"), COleVariant("A1"));
              m\_ebCellA1.GetWindowText(strText);
              range.SetValue(COleVariant(strText));
              
              range = sheet.GetRange(COleVariant("A2"), COleVariant("A2"));
              m\_ebCellA2.GetWindowText(strText);
              range.SetValue(COleVariant(strText));
          
              range = sheet.GetRange(COleVariant("A4"), COleVariant("A4"));
              range.SetFormula(COleVariant("=A1 + A2"));
          }
          

          Here's a Word example:

          CString         strFileName;
          \_Application    app;
          Documents       docs;
          \_Document       doc;
          COleVariant     vtOptional((long) DISP\_E\_PARAMNOTFOUND, VT\_ERROR), 
                          vtFalse((short) FALSE),
                          vtTrue((short) TRUE);
          
          
          if (app.CreateDispatch("Word.Application") == TRUE)
          {
              docs = app.GetDocuments();
          
              m\_ebDocName.GetWindowText(strFileName);
          
              doc = docs.Open(COleVariant(strFileName), vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional);
          
              doc.PrintOut(vtFalse, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional);
          
              while (app.GetBackgroundPrintingStatus() > 0)
                  ;
          
              docs.Close(vtFalse, vtOptional, vtOptional);
          
              app.Quit(vtOptional, vtOptional, vtOptional);
          }
          
          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Wow, It is nice to see that my serving my purpose is not that tough. thanks for the info, thanks a lot. cheers mahanare:-D

          M 1 Reply Last reply
          0
          • D Dimitris Vasiliadis

            You could use ODBC and treat EXCEL sheets like tables. Take a look at: http://www.codeproject.com/database/excel_odbc_write.asp http://www.codeproject.com/database/excel_odbc.asp

            H Offline
            H Offline
            harinath
            wrote on last edited by
            #5

            thank you, I will this method then I will get back to you, If i get any more doubts. thanks for the attention and the time you spared for me. bye harinath Harinath Reddy HOneywell Technology Solutions Lab, Bangalore, India-560076 harinath@vandemataram.com

            1 Reply Last reply
            0
            • A Anonymous

              Wow, It is nice to see that my serving my purpose is not that tough. thanks for the info, thanks a lot. cheers mahanare:-D

              M Offline
              M Offline
              Michael Pauli
              wrote on last edited by
              #6

              I agree - Automation is a way. BUT don't forget COM - it's much easier and less complicated then the snippets. COM hides all the details. If you are interested - contact me for an example using COM. Regards Michael Mogensen. mm it-consult dk.

              D 1 Reply Last reply
              0
              • M Michael Pauli

                I agree - Automation is a way. BUT don't forget COM - it's much easier and less complicated then the snippets. COM hides all the details. If you are interested - contact me for an example using COM. Regards Michael Mogensen. mm it-consult dk.

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

                Michael Mogensen wrote: Automation is a way. BUT don't forget COM - it's much easier and less complicated... Automation and COM are not mutually exclusive. Remember that Automation is a technology based on the Component Object Model, that enables interoperability among components such as ActiveX. It makes it possible for one application to manipulate objects implemented in another application, or to "expose" objects so they can be manipulated by another.

                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