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