excel.h - Automating Excel... How to Create new worksheets

Discussion in 'C++' started by Jona, Jul 6, 2007.

  1. Jona

    Jona Guest

    Hi, I'm trying to create new Worksheets in my code but I really have
    no clue how to...
    here is part of my code.
    Thanks for your help in advance.

    //Header declarations..
    _Application xlApp;
    Workbooks wb;
    _Workbook _wb;
    Worksheets ws;

    //Source
    //Add Workbook
    wb = xlApp.GetWorkbooks();
    _wb = wb.Add(covOptional);
    ws = _wb.GetSheets();

    //Remove the 3 default sheets
    _Worksheet selSheet;
    selSheet = ws.GetItem(COleVariant((short)1));
    selSheet.Delete();
    selSheet = ws.GetItem(COleVariant((short)2));
    selSheet.Delete();
    selSheet = ws.GetItem(COleVariant((short)3));
    selSheet.Delete();



    If you want to rename any of these sheets is really easy//
    selSheet = ws.GetItem(COleVariant((short)2));
    selSheet.SetName("NonInteractive Mode Results");

    -Jona
     
    Jona, Jul 6, 2007
    #1
    1. Advertising

  2. Jona

    shadowman Guest

    Jona wrote:
    > Hi, I'm trying to create new Worksheets in my code but I really have
    > no clue how to...
    > here is part of my code.
    > Thanks for your help in advance.
    >
    > //Header declarations..
    > _Application xlApp;
    > Workbooks wb;
    > _Workbook _wb;
    > Worksheets ws;
    >
    > //Source
    > //Add Workbook
    > wb = xlApp.GetWorkbooks();
    > _wb = wb.Add(covOptional);
    > ws = _wb.GetSheets();
    >
    > //Remove the 3 default sheets
    > _Worksheet selSheet;
    > selSheet = ws.GetItem(COleVariant((short)1));
    > selSheet.Delete();
    > selSheet = ws.GetItem(COleVariant((short)2));
    > selSheet.Delete();
    > selSheet = ws.GetItem(COleVariant((short)3));
    > selSheet.Delete();
    >
    >
    >
    > If you want to rename any of these sheets is really easy//
    > selSheet = ws.GetItem(COleVariant((short)2));
    > selSheet.SetName("NonInteractive Mode Results");
    >
    > -Jona
    >

    Try microsoft.public.excel.programming
     
    shadowman, Jul 6, 2007
    #2
    1. Advertising

  3. Jona wrote:
    > Hi, I'm trying to create new Worksheets in my code but I really have
    > no clue how to...


    Neither do we. There is no definition of "Excel" or "worksheet" in
    C++ _language_. You need to ask in the newsgroup dedicated to Excel
    and/or whatever toolkit you're using. Try the 'microsoft.public.*'
    hierarchy.

    > [..]


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jul 6, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nik
    Replies:
    1
    Views:
    1,270
    ardent.alan
    Mar 21, 2012
  2. Replies:
    2
    Views:
    1,457
    Mark Rae
    Nov 27, 2006
Loading...

Share This Page