我最终使用了,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" );