使用 OLE 获取焦点中的 Excel 工作表的 ID

发布于 2024-07-29 19:29:55 字数 313 浏览 9 评论 0原文

使用 C++ 和 OLE,我如何获取当前焦点工作表的 ID?

例如,我有以下代码:

    Variant excelSheets;
    Variant excelSheet;

    excelSheets.OleProcedure("Add");
    excelSheet= excelSheets.OlePropertyGet("Item", 1);

我想添加一个工作表,然后获取刚刚添加的工作表,以便我可以添加内容。 仅当用户不将焦点从最左侧的工作表上移开时,上述代码才有效。

赛斯

Using C++ and OLE, how might I go about obtaining the ID of the worksheet that is currently in focus?

For example, I have the following code:

    Variant excelSheets;
    Variant excelSheet;

    excelSheets.OleProcedure("Add");
    excelSheet= excelSheets.OlePropertyGet("Item", 1);

I would like to add a sheet and then get the sheet that was just added so that I may add content. The above code only works if the user doesn't shift focus away from the sheet which is at the far left.

Seth

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伏妖词 2024-08-05 19:29:55

我最终使用了 OlePropertyGet( "ActiveSheet" ); 因为当您添加工作表时,它会变成 ActiveSheet,您可以从那里使用它。 我在下面举了一个我所做的例子:

    Variant excelApp;
    Variant excelBooks; 
    Variant excelWorkBook; 
    Variant excelSheet; 
    Variant excelSheets;

    try
    {
        mExcelApp = Variant::GetActiveObject("Excel.Application");
    }
    catch(EOleSysError& e)
    {
        mExcelApp = Variant::CreateObject("Excel.Application"); //open excel
    }
    catch(...)
    {
        throw;
    }

    mExcelApp.OlePropertySet("ScreenUpdating", true);
    excelBooks = mExcelApp.OlePropertyGet("Workbooks");
    excelWorkBook = excelBooks.OlePropertyGet("Item",1);

    // a worksheet is added which becomes the active sheet
    excelSheets.OleProcedure( "Add" );
    excelSheet = excelWorkBook.OlePropertyGet( "ActiveSheet" );

I ended up using OlePropertyGet( "ActiveSheet" ); because when you add a sheet it becomes the ActiveSheet and you can work with it from there. I put an example of what I did below:

    Variant excelApp;
    Variant excelBooks; 
    Variant excelWorkBook; 
    Variant excelSheet; 
    Variant excelSheets;

    try
    {
        mExcelApp = Variant::GetActiveObject("Excel.Application");
    }
    catch(EOleSysError& e)
    {
        mExcelApp = Variant::CreateObject("Excel.Application"); //open excel
    }
    catch(...)
    {
        throw;
    }

    mExcelApp.OlePropertySet("ScreenUpdating", true);
    excelBooks = mExcelApp.OlePropertyGet("Workbooks");
    excelWorkBook = excelBooks.OlePropertyGet("Item",1);

    // a worksheet is added which becomes the active sheet
    excelSheets.OleProcedure( "Add" );
    excelSheet = excelWorkBook.OlePropertyGet( "ActiveSheet" );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文