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. Insert new row in Excel using MFC VC++

Insert new row in Excel using MFC VC++

Scheduled Pinned Locked Moved C / C++ / MFC
c++comtestingtoolstutorial
6 Posts 2 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.
  • S Offline
    S Offline
    spalanivel
    wrote on last edited by
    #1

    Hi, I am using a VC++ MFC app to drive Excel through OLE Automation. I need to insert new row in the Excel. How to acheive this? *************** // Code Sample *************** // excel application object Application objExcel; // local var COleVariant vRet; // range object Range objRange; // set the workbooks object Workbooks objWorkbooks( V_DISPATCH( (LPVARIANT)vRet ) ); // adding the new workbook vRet = objWorkbooks.Add( COleVariant( (long)xlWorksheet ) ); // set the workbook object Workbook objWorkbook( V_DISPATCH( (LPVARIANT)vRet ) ); // adding the worksheet vRet = objWorkbook.Worksheets( COleVariant( (long)1 ) ); Worksheet objWorksheet( V_DISPATCH( (LPVARIANT)vRet ) ); // get the range vRet = objWorksheet.Range1( COleVariant( csRange ) ); objRange.AttachDispatch( V_DISPATCH( (LPVARIANT)vRet ) ); From the above code in objRange having the Row position as C8. Here need to insert a new row. Reg, SPala

    D 1 Reply Last reply
    0
    • S spalanivel

      Hi, I am using a VC++ MFC app to drive Excel through OLE Automation. I need to insert new row in the Excel. How to acheive this? *************** // Code Sample *************** // excel application object Application objExcel; // local var COleVariant vRet; // range object Range objRange; // set the workbooks object Workbooks objWorkbooks( V_DISPATCH( (LPVARIANT)vRet ) ); // adding the new workbook vRet = objWorkbooks.Add( COleVariant( (long)xlWorksheet ) ); // set the workbook object Workbook objWorkbook( V_DISPATCH( (LPVARIANT)vRet ) ); // adding the worksheet vRet = objWorkbook.Worksheets( COleVariant( (long)1 ) ); Worksheet objWorksheet( V_DISPATCH( (LPVARIANT)vRet ) ); // get the range vRet = objWorksheet.Range1( COleVariant( csRange ) ); objRange.AttachDispatch( V_DISPATCH( (LPVARIANT)vRet ) ); From the above code in objRange having the Row position as C8. Here need to insert a new row. Reg, SPala

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

      Have you tried objRange.Insert()?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather

      S 1 Reply Last reply
      0
      • D David Crow

        Have you tried objRange.Insert()?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather

        S Offline
        S Offline
        spalanivel
        wrote on last edited by
        #3

        Hi David, Thanks for your reply. I am using Excel 2007. Yes i tried with Insert method. I don't how to give the Parameter value; Below is my code:

        csRange.Format("C%d", nRow );
        // get the range
        vRet = objWorksheet.Range1( COleVariant( csRange ) );
        objRange.AttachDispatch( V_DISPATCH( (LPVARIANT)vRet ) );

        objRange.Insert(???) ********************************** sy****natx for Insert: objRange.Insert(const VARIANT &shift) ************************************** How to give the parameter value for Insert method? Waiting for your reply. Thanks, SPala

        D 1 Reply Last reply
        0
        • S spalanivel

          Hi David, Thanks for your reply. I am using Excel 2007. Yes i tried with Insert method. I don't how to give the Parameter value; Below is my code:

          csRange.Format("C%d", nRow );
          // get the range
          vRet = objWorksheet.Range1( COleVariant( csRange ) );
          objRange.AttachDispatch( V_DISPATCH( (LPVARIANT)vRet ) );

          objRange.Insert(???) ********************************** sy****natx for Insert: objRange.Insert(const VARIANT &shift) ************************************** How to give the parameter value for Insert method? Waiting for your reply. Thanks, SPala

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

          spalanivel wrote:

          How to give the parameter value for Insert method?

          Have you tried something like:

          objRange.Insert(COleVariant(-4121L), vtOptional);

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather

          S 1 Reply Last reply
          0
          • D David Crow

            spalanivel wrote:

            How to give the parameter value for Insert method?

            Have you tried something like:

            objRange.Insert(COleVariant(-4121L), vtOptional);

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather

            S Offline
            S Offline
            spalanivel
            wrote on last edited by
            #5

            I tried with the below codes but still no luck...

            csRange.Format("C%d", nRow );
            objWorksheet.Range( COleVariant(csRange), vtOptional);

            and objRange.Insert(COleVariant(-4121L), vtOptional); Following Error Message while i tried with the above code "Memeber Not Found".. Any other option? Just need to insert a new row i am using Excel 2007 and excel9.h header file. Thanks.

            D 1 Reply Last reply
            0
            • S spalanivel

              I tried with the below codes but still no luck...

              csRange.Format("C%d", nRow );
              objWorksheet.Range( COleVariant(csRange), vtOptional);

              and objRange.Insert(COleVariant(-4121L), vtOptional); Following Error Message while i tried with the above code "Memeber Not Found".. Any other option? Just need to insert a new row i am using Excel 2007 and excel9.h header file. Thanks.

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

              spalanivel wrote:

              Following Error Message while i tried with the above code "Memeber Not Found"..

              What member is the compiler referring to?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather

              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