void MainWindow::on_createNewSheet_clicked() { try { int sheetsCount=work_sheets->property("Count").toUInt(); // cout<<"sheetsCount="<<sheetsCount<<endl; //获取最后一个sheet的指针 QAxObject * pLastSheet = work_sheets->querySubObject("Item(int)",sheetsCount); // work_sheet =work_sheets->querySubObject("Item(int)",sheetsCount); //添加新sheet,此时默认在pLastSheet之前插入。 pLastSheet->dynamicCall("Activate()"); QAxObject* newSheet= work_sheets->querySubObject("Add()"); //为了把新插入的工作表放到所有sheets的最后,需要pLastSheet移动(move)到newSheet之后。 newSheet->dynamicCall("Move(QVariant)",work_sheet->asVariant()); pLastSheet->dynamicCall("Move(QVariant)",newSheet->asVariant()); //下面是给新的sheet起个名字。 QDate date; QString currentDate=date.currentDate().toString(); QString sheetName=QString("choosed Student ")+(currentDate); newSheet->setProperty("Name",sheetName); } catch (...) { qCritical()<<"创建sheet失败..."; } }
标签:pLastSheet,sheet,Qt,int,work,sheets,newSheet From: https://www.cnblogs.com/phoenixdsg/p/17278771.html