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. Add new sheet in Excel using mfc...

Add new sheet in Excel using mfc...

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasehelptutorialquestion
2 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 need to add worksheets(like sheet2,sheet3,...) with the below exising code. Now sheet1 is coming by default and able to write the contents. Existing Code: -------------- COleException objEx; // exception object Application objExcel; // excel application object // local var COleVariant vRet; // row index long nRow = 1; // range object Range objRange; // create the excel object objExcel.CreateDispatch( "Excel.Application", &objEx ); // show the application objExcel.SetVisible( COleVariant(short(FALSE)) ); // get the workbooks object vRet = objExcel.Workbooks2(); // 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 ) ); // set the worksheet object Worksheet objWorksheet( V_DISPATCH( (LPVARIANT)vRet ) ); How to add more sheets with the above code? Please help. I am using below header files;

    #include "XL5EN32.H"
    #include "excel9.h"
    #include "ExcelObject.h"

    Thanks, Pala

    _ 1 Reply Last reply
    0
    • S spalanivel

      Hi, I need to add worksheets(like sheet2,sheet3,...) with the below exising code. Now sheet1 is coming by default and able to write the contents. Existing Code: -------------- COleException objEx; // exception object Application objExcel; // excel application object // local var COleVariant vRet; // row index long nRow = 1; // range object Range objRange; // create the excel object objExcel.CreateDispatch( "Excel.Application", &objEx ); // show the application objExcel.SetVisible( COleVariant(short(FALSE)) ); // get the workbooks object vRet = objExcel.Workbooks2(); // 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 ) ); // set the worksheet object Worksheet objWorksheet( V_DISPATCH( (LPVARIANT)vRet ) ); How to add more sheets with the above code? Please help. I am using below header files;

      #include "XL5EN32.H"
      #include "excel9.h"
      #include "ExcelObject.h"

      Thanks, Pala

      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #2

      Did you try this[^] class ?

      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