void SportsmenReport::writeBody(const char *headers[], uint length) { sheet = openDocument(); for(uint i = 0; i < length; ++i) { QAxObject *range = sheet->querySubObject("Range(const QString&)", QString('A'+i) + QString::number(1)); range->dynamicCall("SetValue(const QVariant&)", QObject::tr(headers[i])); range->querySubObject("Font")->setProperty("Bold", true); range->querySubObject("Borders")->setProperty("LineStyle", xlSingle); } int rowid = 2, fieldsCount = length; while(query->next()) { fieldsCount = query->record().count(); for(int i = 0; i < fieldsCount; ++i) { QAxObject *range = sheet->querySubObject("Range(const QString&)", QString('A'+i) + QString::number(rowid)); range->dynamicCall("SetValue(const QVariant&)", QVariant(query->value(i).value<QString>())); } rowid++; } QAxObject *exported = sheet->querySubObject("Range(const QString&)", (QString("A2:") + (QString('A'+(fieldsCount-1)) + QString::number(rowid-1)))); exported->querySubObject("Borders")->setProperty("LineStyle", xlSingle); QAxObject *font = exported->querySubObject("Font"); font->setProperty("Name", QObject::tr("Arial")); font->setProperty("Size", 10); sheet->querySubObject("Columns")->dynamicCall("AutoFit()"); }
void MyTable::printFile(const QString& fileName) { qDebug() << "PrintFile" << fileName; #ifdef EXCEL if (!excel->isNull()) { if (excel->Workbooks()->Open(fileName)) { Excel::_Worksheet sheet(excel->ActiveSheet()); sheet.PrintOut(1, 1, 1); excel->Workbooks()->Close(); //ActiveWorkbook()->Close(false); } } #else QAxObject* excel = new QAxObject("Excel.Application", 0); excel->dynamicCall("SetVisible(bool)", true); QAxObject* workbooks = excel->querySubObject("Workbooks"); QAxObject* workbook = workbooks->querySubObject("Open(const QString&)", fileName); QAxObject* sheets = workbook->querySubObject("Worksheets"); if (workbooks->dynamicCall("Count()").toInt()) { QAxObject* sheet = sheets->querySubObject("Item(int)", 1); sheet->dynamicCall("PrintOut(QVariant, QVariant, QVariant)", 1, 1, 1); workbook->dynamicCall("Close()"); } excel->dynamicCall("Quit()"); excel->deleteLater(); #endif }
//AC.template.verifiedRecord void MainWidget::init_word() { QAxWidget word("Word.Application"); word.setProperty("Visible", false);//隐式的打开一个word应用程序 QAxObject * documents = word.querySubObject("Documents"); //获取所有工作文档 documents->dynamicCall("Add (void)");//创建一个word文档 QAxObject * document = word.querySubObject("ActiveDocument"); //获取当前激活的文档 QAxObject *selection = word.querySubObject("Selection"); //写入文件内容 QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间 QString str = time.toString("yyyy-MM-dd hh:mm:ss ddd"); //设置显示格式 selection->dynamicCall("TypeText(const QString&)","hello"+str); //设置保存 QVariant newFileName("e:/test.doc"); //存放位置和名称 QVariant fileFormat(1); //文件格式 QVariant LockComments(false); QVariant Password(""); //设置打开密码 QVariant recent(true); QVariant writePassword(""); QVariant ReadOnlyRecommended(false); document->querySubObject("SaveAs(const QVariant&, const QVariant&,const QVariant&, const QVariant&, const QVariant&, const QVariant&,const QVariant&)", newFileName, fileFormat, LockComments, Password, recent, writePassword, ReadOnlyRecommended); document->dynamicCall("Close (boolean)", true); //关闭文档 word.dynamicCall("Quit (void)");//退出 }
void TechnicalReport::writeHeader() { QAxObject *range = getRange(QString("A%1:B%1").arg(currentRow)); range->dynamicCall("Merge()"); range->dynamicCall("SetValue(const QVariant&)", QObject::tr("Категория ") + query->value(1).value<QString>()); currentRow++; }
void TechnicalReport::writeSuperHeader() { QAxObject *range = getRange(QString("A%1:B%1").arg(currentRow)); range->dynamicCall("Merge()"); range->dynamicCall("SetValue(const QVariant&)", QObject::tr("Технические результаты ") + query->value(0).value<QString>() + " " + query->value(2).value<QDate>().toString("dd.MM.yyyy")); currentRow++; }
bool ItemsList::generateSchedule() { if (!m_actualTable.isEmpty() && mainOrderActive ) { setAnimationVisible(true); emit animationVisible(getAnimationVisible()); if( setPath().isEmpty() ) { runMsg("Nie wybrano lokalizacji."); setAnimationVisible(false); emit animationVisible(getAnimationVisible()); return false; } QAxObject* excel; QAxObject* wbooks; QAxObject* book; QFileInfo scheduleFile("schedule.xlsm"); QVariant excelPath; QVariant destPath; excelPath = QVariant(scheduleFile.absoluteFilePath().replace("/", "\\\\")); excel = new QAxObject("Excel.Application", this); excel->setProperty("Visible", false); excel->setProperty("DisplayAlerts",0); wbooks = excel->querySubObject("Workbooks"); book = wbooks->querySubObject("Open (const QString&)", excelPath); destPath = excel->dynamicCall("Run(QVariant)", QVariant("runMacro")); book->dynamicCall("Close()"); excel->dynamicCall("Quit()"); runMsg("Wygenerowano harmonogram",destPath.toString()); delete book; delete wbooks; delete excel; setAnimationVisible(false); emit animationVisible(getAnimationVisible()); csvFile->remove(); tableDialog->model->clear(); mainOrderActive = false; return true; } else if(m_actualTable.isEmpty() || !mainOrderActive ) { runMsg("Zamówienie jest puste."); return false; } return false; }
void MainWindow::on_btnExport_clicked() { QDir dir(QDir::currentPath()); QDate date; QSettings config(dir.currentPath()+"//app.ini",QSettings::IniFormat); QString path = config.value("/SETTINGS/path").toString(); QString fileName = QFileDialog::getSaveFileName(this,tr("保存文件"),path + "/" + date.currentDate().toString("yyyy-MM-dd")+ui->cbWareH->currentText()+".xls",tr("Microsoft Office 2003(*.xls)")); if(fileName.isEmpty()){ QMessageBox::critical(0,tr("错误"),tr("要保存的文件名为空")); return; } QSqlQuery query; query.exec(QString("execute dbo.pr_report_jxc_item;1 @as_from = '%1', @as_to = '%2', @as_branch = '%3', @as_itemcls = '%'") .arg(date.currentDate().toString("yyyy-MM-dd")) .arg(date.currentDate().toString("yyyy-MM-dd")) .arg(ui->cbWareH->currentData().toString())); QAxObject *excel = new QAxObject("Excel.Application"); if(!excel){ QMessageBox::critical(0,tr("错误"),tr("找不到Excel组件!")); delete excel; return; } excel->dynamicCall("SetVisible(bool)",false); excel->setProperty("Visible", false); excel->setProperty("DisplayAlerts", false); QAxObject *workbooks = excel->querySubObject("WorkBooks"); workbooks->dynamicCall("Add"); QAxObject *workbook = excel->querySubObject("ActiveWorkBook"); QAxObject *worksheets = workbook->querySubObject("Sheets"); QAxObject *worksheet = worksheets->querySubObject("Item(int)",1); int row = 1; while(query.next()){ setCellValue(worksheet,row,"A","'"+query.value("cItem_C").toString()); setCellValue(worksheet,row,"B","'"+query.value("cItem_N").toString()); setCellValue(worksheet,row,"C","0"); setCellValue(worksheet,row,"D",query.value("nSettleQty")); row ++; }; workbook->dynamicCall("SaveAs(const QString&)",QDir::toNativeSeparators(fileName)); config.setValue("/SETTINGS/path",fileName.left(fileName.lastIndexOf("/"))); QMessageBox::information(this,tr("操作成功"),tr("保存成功!")); workbook->dynamicCall("Close()"); worksheet->clear(); excel->dynamicCall("Quit()"); delete excel; }
void MainWidget::on_RSMV_buildFrom_PsBtn_clicked() { QString strPath=getTemplatePath(); QFile file(strPath); //qDebug()<<strPath; if (!file.exists()) { show_MsBox(QString::fromUtf8("找不到报表模板路径"),3000); } #if 1 QAxWidget* temp_AxWidget = new QAxWidget("Word.Application"); temp_AxWidget->setProperty("Visible", true); //新建一个word应用程序,并设置为可见 QAxObject* documents = temp_AxWidget->querySubObject("Documents"); //获取所有的工作文档 documents->dynamicCall("Open(QVariant)",strPath ); //路径不对打开奔溃 QAxObject *selection = temp_AxWidget->querySubObject("Selection"); QAxObject *find = selection->querySubObject("Find"); QList<QVariant> list2; //*****Find Word http://technet.microsoft.com/zh-cn/library/ff193977 list2.append("{cUserName}"); //find text list2.append(QVariant());//2 list2.append(QVariant());//3 list2.append(QVariant());//4 list2.append(QVariant());//5 list2.append(QVariant());//6 list2.append(QVariant());//7 list2.append(QVariant());//8 list2.append(QVariant());//9 list2.append(QString::fromUtf8("深圳市星龙科技")); //replace text list2.append(2);//replace all:2 list2.append(QVariant());//12 list2.append(QVariant());//13 list2.append(QVariant());//14 list2.append(QVariant());//15 replaceDocTypeList replaceDocTypeList_Data; //装载搜索内容和替换内容的列表 fillReplaceDocTypeList(ui->from_information_TbWidget,&replaceDocTypeList_Data); for (int i = 0; i < replaceDocTypeList_Data.count(); i++) { list2.replace(0, replaceDocTypeList_Data.at(i).searchStr); list2.replace(9, replaceDocTypeList_Data.at(i).replaceStr); find->dynamicCall("Execute (QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant& ,QVariant& ,QVariant& , QVariant&, QVariant&, QVariant&, QVariant&)", list2); //qDebug()<<replaceDocTypeList_Data.at(i).replaceStr; } #endif // documents->dynamicCall("Save()");//保存 // documents->dynamicCall("Close(boolean)", true);//关闭文本窗口 // temp_AxWidget->dynamicCall("Quit(void)");//退出word }
void ResultsReport::writeHeader(const QString &category, const QString &competition, const QDate &date) { uint offset = (currentPage - 1) * pageHeight + 1; QAxObject *range = getRange(QString("A%1:K%1").arg(offset)); range->dynamicCall("Merge()"); range->dynamicCall("SetValue(const QVariant&)", QObject::tr("Протокол результатов соревнований")); range->setProperty("HorizontalAlignment", xlCenter); range->querySubObject("Font")->setProperty("Name", "Times New Roman"); range->querySubObject("Font")->setProperty("Size", 14); range->querySubObject("Font")->setProperty("Bold", true); offset++; range = getRange(QString("A%1:K%1").arg(offset)); range->dynamicCall("Merge()"); range->dynamicCall("SetValue(const QVariant&)", competition); range->setProperty("HorizontalAlignment", xlCenter); range->querySubObject("Font")->setProperty("Name", "Times New Roman"); range->querySubObject("Font")->setProperty("Size", 14); range->querySubObject("Font")->setProperty("Bold", true); offset++; range = getRange(QString("A%1:K%1").arg(offset)); range->dynamicCall("Merge()"); range->dynamicCall("SetValue(const QVariant&)", QObject::tr("СК «Бастион», ") + genitiveDate(date)); range->setProperty("HorizontalAlignment", xlCenter); range->querySubObject("Font")->setProperty("Name", "Times New Roman"); range->querySubObject("Font")->setProperty("Size", 14); range->querySubObject("Font")->setProperty("Bold", true); offset+=2; range = getRange(QString("A%1:K%1").arg(offset)); range->dynamicCall("Merge()"); range->dynamicCall("SetValue(const QVariant&)", QObject::tr("категория ") + category); range->setProperty("HorizontalAlignment", xlCenter); range->querySubObject("Font")->setProperty("Name", "Times New Roman"); range->querySubObject("Font")->setProperty("Size", 12); range->querySubObject("Font")->setProperty("Bold", true); offset++; const char *headers[] = { "№ п/п", "ФИО", "Год рожд.", "Техн. квалиф. разряд", "Область, край, республика", "Город, населенный пункт", "Д.С.О. Ведомство", "СК, ДЮСШ, СДЮСШОР", "Ф.И.О. Тренера", "Кол-во боев/ побед", "Занятое место", }; for(uint i = 0; i < sizeof(headers)/sizeof(*headers); ++i) { QAxObject *range = getRange(QString('A' + i) + QString::number(offset)); range->dynamicCall("SetValue(const QVariant&)", QObject::tr(headers[i])); } }
/** *@brief 从指定的xls文件中把数据导入到tableWidget中 *@param tableWidget : 执行要导入到的tablewidget指针 *@return 导入成功与否 true : 成功 * false: 失败 */ bool ExcelEngine::readDataToTable(QTableWidget *tableWidget) { if ( NULL == tableWidget ) { return false; } //先把table的内容清空 int tableColumn = tableWidget->columnCount(); tableWidget->clear(); for (int n=0; n<tableColumn; n++) { tableWidget->removeColumn(0); } int rowcnt = nStartRow + nRowCount; int columncnt = nStartColumn + nColumnCount; //获取excel中的第一行数据作为表头 QStringList headerList; for (int n = nStartColumn; n<columncnt; n++ ) { QAxObject * cell = pWorksheet->querySubObject("Cells(int,int)",nStartRow, n); if ( cell ) { headerList<<cell->dynamicCall("Value2()").toString(); } } //重新创建表头 tableWidget->setColumnCount(nColumnCount); tableWidget->setHorizontalHeaderLabels(headerList); //插入新数据 for (int i = nStartRow+1, r = 0; i < rowcnt; i++, r++ ) //行 { tableWidget->insertRow(r); //插入新行 for (int j = nStartColumn, c = 0; j < columncnt; j++, c++ ) //列 { QAxObject * cell = pWorksheet->querySubObject("Cells(int,int)", i, j );//获取单元格 //在r新行中添加子项数据 if ( cell ) { tableWidget->setItem(r,c,new QTableWidgetItem(cell->dynamicCall("Value2()").toString())); } } } return true; }
unsigned int WINAPI TextSpeech::ThreadTextToSpeech(void *arg) { CoInitialize(NULL); QAxObject voiceObj; bool bSuccess = voiceObj.setControl("96749377-3391-11D2-9EE3-00C04F797396"); if(bSuccess) { voiceObj.dynamicCall("SetRate(int)",-3).toInt(); voiceObj.dynamicCall("Speak(QString,SpeechVoiceSpeakFlags)",((TextSpeech *)arg)->m_strToSpeak,0).toInt(); } CoUninitialize(); ((TextSpeech *)arg)->SpeakThreadComplete(); return 0; }
bool Excel::writeRow(int row, QVariantList &list) { try { char sCell[18]; memset(sCell, 0, 18); int col = list.count(); if (col <= 26) sprintf(sCell, " %c", 'A' + col - 1); else sprintf(sCell, "%c%c", 'A' + col / 26 - 1, 'A' + col % 26 - 1); QString cell = sCell; columnName = columnName.toUpper() > cell.toUpper() ? columnName : cell; cell = cell.trimmed() + QString::number(row); QString srange = "Range(\"A" + QString::number(row) + "\",\"" + cell + "\")"; if (!excelSheet) return false; QAxObject *range = excelSheet->querySubObject(srange.toLocal8Bit()); if (!range) return false; range->dynamicCall("SetValue2(const QVariantList&)", QVariant(list)); delete range; return true; } catch (...) { return false; } }
void test2() { QAxObject* excel = new QAxObject( "Excel.Application", 0); excel->setProperty("Visible", true); excel->dynamicCall("Quit()"); delete excel; }
/** * @brief Create Excel File * @param file [QString] the name of the opened file * @return 0:success -1:failed */ bool QEXCEL::CreateExcel(QString file) { QDir dTemp; if(dTemp.exists(file)) { qDebug()<<" QExcel::CreateExcel: exist file"<<file; return false; } qDebug()<<" QExcel::CreateExcel: succes"; /**< create new excel sheet file.*/ QAxObject * workSheet = excel->querySubObject("WorkBooks"); workSheet->dynamicCall("Add"); /**< save Excel.*/ QAxObject * workExcel= excel->querySubObject("ActiveWorkBook"); excel->setProperty("DisplayAlerts", 0); workExcel->dynamicCall("SaveAs (const QString&,int,const QString&,const QString&,bool,bool)",file,56,QString(""),QString(""),false,false); excel->setProperty("DisplayAlerts", 1); workExcel->dynamicCall("Close (Boolean)", false); /**< exit Excel.*/ //excel->dynamicCall("Quit (void)"); return true; }
void QEXCEL::clearCell(int row, int column) { QString cell; cell.append(QChar(column - 1 + 'A')); cell.append(QString::number(row)); QAxObject *range = sheet->querySubObject("Range(const QString&)", cell); range->dynamicCall("ClearContents()"); }
void PulkaReport::writeRec(uint draw_number) { bool right = draw_number > 8; draw_number = (draw_number - 1) % 8; uint offset = (currentPage - 1) * pageHeight + firstRecOffset + draw_number * 4; QAxObject *range = getRange((right ? QString("L%1:M%2") : QString("A%1:B%2")).arg(offset).arg(offset + 1)); range->dynamicCall("SetValue(const QVariant&)", query->value(3).toString() + " " + query->value(4).toString() + " " + query->value(5).toString()); }
void DrawingReport::writeFooter(uint written) { for(int i = written; i < 16; ++i, ++currentRow) { QAxObject *range = sheet->querySubObject("Range(const QString&)", QString('A') + QString::number(currentRow)); range->dynamicCall("SetValue(const QVariant&)", QString::number(i+1)); } QAxObject *range0 = sheet->querySubObject("Range(const QString&)", QString('A') + QString::number(currentRow-16) + QString(":") + QString('A' + 5) + QString::number(currentRow-1)); range0->querySubObject("Borders")->setProperty("LineStyle", xlSingle); range0->setProperty("RowHeight", 39); range0->setProperty("WrapText", true); QAxObject *range1 = getRange(QString("A%1:A%2").arg(currentRow - 16).arg(currentRow - 1)), *range2 = getRange(QString("B%1:F%2").arg(currentRow - 16).arg(currentRow - 1)), *range3 = getRange(QString("A%1:F%2").arg(currentRow - 16).arg(currentRow - 1)); range3->setProperty("WrapText", true); range1->setProperty("HorizontalAlignment", xlRight); range1->setProperty("VerticalAlignment", xlBottom); QAxObject *font1 = range1->querySubObject("Font"); font1->setProperty("Name", QString("Arial Cyr")); font1->setProperty("Size", 12); font1->setProperty("Bold", true); range2->setProperty("VerticalAlignment", xlTop); QAxObject *font2 = range2->querySubObject("Font"); font2->setProperty("Name", QString("Calibri")); font2->setProperty("Size", 10); currentRow++; QAxObject *judge = getRange(QString("B%1").arg(currentRow)); judge->dynamicCall("SetValue(const QVarialnt&)", QObject::tr("Гл. судья")); QAxObject *secr = getRange(QString("D%1:E%1").arg(currentRow)); secr->dynamicCall("Merge()"); secr->dynamicCall("SetValue(const QVarialnt&)", QObject::tr("Гл. секретарь")); QAxObject *js[] = {judge, secr}; for(uint i = 0; i < sizeof(js)/sizeof(*js); ++i) { js[i]->querySubObject("Borders(int)", xlEdgeBottom)->setProperty("LineStyle", xlSingle); QAxObject *font = js[i]->querySubObject("Font"); font->setProperty("Name", "Arial Cyr"); font->setProperty("Size", 10); font->setProperty("Bold", true); } currentRow += 7; currentPage++; }
QAxObject *BaseReport::openDocument() { excel = new QAxObject("Excel.Application", 0); excel->dynamicCall("SetVisible(bool)", true); QAxObject *workbooks = excel->querySubObject("Workbooks"); QAxObject *workbook = workbooks->querySubObject("Add()"); QAxObject *sheet = workbook->querySubObject("ActiveSheet"); sheet->dynamicCall( "Select()" ); return sheet; }
void QEXCEL::setAutoFitRow(int row) { QString rowsName; rowsName.append(QString::number(row)); rowsName.append(":"); rowsName.append(QString::number(row)); QAxObject * rows = sheet->querySubObject("Rows(const QString &)", rowsName); rows->dynamicCall("AutoFit()"); }
void ResultsReport::writeFooter() { uint offset = currentPage * pageHeight - 15; QAxObject *range = getRange(QString("A%1:B%1").arg(offset - 1)), *range2 = getRange(QString("A%1:B%1").arg(offset)); range->dynamicCall("Merge()"); range2->dynamicCall("Merge()"); range->dynamicCall("SetValue(const QVariant&)", QObject::tr("Гл. судья")); range2->dynamicCall("SetValue(const QVariant&)", QObject::tr("Гл. секретарь")); range = getRange(QString("C%1:E%1").arg(offset - 1)), range2 = getRange(QString("C%1:E%1").arg(offset)); range->dynamicCall("Merge()"); range2->dynamicCall("Merge()"); range->dynamicCall("SetValue(const QVariant&)", QObject::tr("Григорьев Д.А.")); range2->dynamicCall("SetValue(const QVariant&)", QObject::tr("Штаненкова Ж.Л.")); range->querySubObject("Font")->setProperty("Name", "Times New Roman"); range2->querySubObject("Font")->setProperty("Name", "Times New Roman"); range->querySubObject("Font")->setProperty("Size", 12); range2->querySubObject("Font")->setProperty("Size", 12); range = getRange(QString("A%1:K%2").arg(offset - 12).arg(offset - 4)); range->querySubObject("Borders")->setProperty("LineStyle", xlSingle); range->querySubObject("Font")->setProperty("Name", "Times New Roman"); range->setProperty("WrapText", true); range = getRange(QString("A%1:K%2").arg(offset - 11).arg(offset - 4)); range->querySubObject("Font")->setProperty("Size", 11); range = getRange(QString("A%1:K%1").arg(offset - 12)); range->querySubObject("Font")->setProperty("Size", 10); range->querySubObject("Font")->setProperty("Bold", true); range->setProperty("HorizontalAlignment", xlCenter); range = getRange(QString("B%1:K%2").arg(offset - 12).arg(offset - 4)); range->setProperty("HorizontalAlignment", xlCenter); currentPage++; }
void TechnicalReport::writeLine() { QAxObject *range = getRange(QString("A%1").arg(currentRow)), *range2 = getRange(QString("B%1").arg(currentRow)); range->dynamicCall("SetValue(const QVariant&)", QString("%1.").arg(query->value(6).value<uint>())); range2->dynamicCall("SetValue(const QVariant&)", QString("%1 (%2 %3)").arg(query->value(3).toString(), query->value(5).toString(), query->value(4).toString())); currentRow++; }
/** *@brief 获取指定单元格的数据 *@param row : 单元格的行号 *@param column : 单元格的列号 *@return [row,column]单元格对应的数据 */ QVariant ExcelEngine::getCellData(UINT row, UINT column) { QVariant data; QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象 if ( cell ) { data = cell->dynamicCall("Value2()"); } return data; }
bool showInWindowsShell(const QString &filePath, bool deselect) { QFileInfo appFI(filePath); auto matchPath = appFI.dir().path().toLower(); auto matchName = appFI.fileName().toLower(); QAxObject shellApp("Shell.Application"); QAxObject *windows = shellApp.querySubObject("Windows()"); windows->disableMetaObject(); auto count = windows->dynamicCall("Count()").toInt(); qDebug() << count; for (int i = 0; i < count; ++i) { QAxObject *win = windows->querySubObject("Item(QVariant)", {i}); win->disableMetaObject(); auto program = win->dynamicCall("FullName()").toString(); QFileInfo programFI(program); if (programFI.baseName().toLower() != "explorer") continue; auto url = win->dynamicCall("LocationURL()").toUrl(); if (!url.isLocalFile()) continue; auto path = url.path().mid(1).toLower(); if (path != matchPath) continue; QAxObject *doc = win->querySubObject("Document()"); QAxObject *folder = doc->querySubObject("Folder()"); folder->disableMetaObject(); QAxObject *folderItems = folder->querySubObject("Items()"); folderItems->disableMetaObject(); QAxObject *ourEntry = {}; int count = folderItems->dynamicCall("Count()").toInt(); for (int j = 0; j < count; j++) { QAxObject *entry = folderItems->querySubObject("Item(QVariant)", j); entry->disableMetaObject(); auto name = entry->dynamicCall("Name()").toString().toLower(); if (name == matchName) ourEntry = entry; } if (ourEntry) { if (false) ourEntry->dynamicCall("InvokeVerb(QVariant)", QVariant()); // open etc. auto rc = doc->dynamicCall("SelectItem(QVariant, int)", ourEntry->asVariant(), SVSI_SELECT | (deselect ? SVSI_DESELECTOTHERS : 0)); auto hwnd = win->dynamicCall("HWND()").toLongLong(); BringWindowToTop(HWND(hwnd)); return true; } } return false; }
void DrawingReport::writeLine(uint written) { sheet->querySubObject("Range(const QString&)", QString('A') + QString::number(currentRow)) ->dynamicCall("SetValue(const QVariant&)", QString::number(written+1)); for(int i = 2, fieldsCount = query->record().count(); i < fieldsCount; ++i) { QAxObject *range = sheet->querySubObject("Range(const QString&)", QString('A'+i-1) + QString::number(currentRow)); range->dynamicCall("SetValue(const QVariant&)", (i != 3 ? query->value(i).value<QString>() : query->value(i).value<QDate>().toString("dd.MM.yyyy"))); } currentRow++; }
void Skype::updateChats() { chats.clear(); QAxObject *obj = this->querySubObject("Chats()"); if(obj != NULL){ const int count = obj->dynamicCall("Count()").toInt(); for(int i = 1; i <= count; i++){ QAxObject *chat = obj->querySubObject("Item(int)", QVariant(i)); if(chat != NULL){ const QString friendlyName = chat->dynamicCall("FriendlyName()").toString(); const QString topic = chat->dynamicCall("Topic()").toString(); if(topic.trimmed().isEmpty()){ if(!friendlyName.isEmpty()){ chats[friendlyName]=chat; } }else{ chats[topic]=chat; } } } } }
void MyTable::loadFile(const QString& fileName) { qDebug() << "LoadFile" << fileName; #ifdef EXCEL if (!excel->isNull()) { Excel::_Workbook pWb(0, excel->Workbooks()->querySubObject("Open(const QString&)", fileName) /*->Open(fileName)*/); if (excel->Workbooks()->Count()) { for (int devCh = 0; devCh < RowCount; ++devCh) { for (int adcCh = 0; adcCh < 2; ++adcCh) { for (int resCh = 0; resCh < 3; ++resCh) { data[devCh][adcCh * 3 + resCh].clear(); if (!adcCh) data[devCh][adcCh * 3 + resCh].append(excel->Range(QString("D%1").arg(6 + devCh * 3 + resCh))->Value().toDouble()); else data[devCh][adcCh * 3 + resCh].append(excel->Range(QString("G%1").arg(6 + devCh * 3 + resCh))->Value().toDouble()); } } Update(devCh); } pWb.Close(); //excel->Workbooks()->Close(); dataChanged = true; resizeEvent(0); } } #else m_curFile = fileName; QAxObject* excel = new QAxObject("Excel.Application", 0); excel->dynamicCall("SetVisible(bool)", true); QAxObject* workbooks = excel->querySubObject("Workbooks"); QAxObject* workbook = workbooks->querySubObject("Open(const QString&)", m_curFile); QAxObject* sheets = workbook->querySubObject("Worksheets"); QVariant value; if (workbooks->dynamicCall("Count()").toInt()) { QAxObject* sheet = sheets->querySubObject("Item(int)", 1); for (int devCh = 0; devCh < RowCount; ++devCh) { m_model->clearData(devCh); for (int adcCh = 0; adcCh < 2; ++adcCh) { for (int resCh = 0; resCh < 3; ++resCh) { if (!adcCh) { QAxObject* cell = sheet->querySubObject("Cells(int,int)", 6 + devCh * 3 + resCh, 4); value = cell->dynamicCall("Value()"); } else { QAxObject* cell = sheet->querySubObject("Cells(int,int)", 6 + devCh * 3 + resCh, 7); value = cell->dynamicCall("Value()"); } m_model->addData(devCh, adcCh * 3 + resCh, value.toDouble()); } } } workbook->dynamicCall("Close()"); resizeEvent(0); } excel->dynamicCall("Quit()"); excel->deleteLater(); resizeRowsToContents(); #endif }
void ExcelOnglet::ajouterLigne( std::vector< std::string > informations ) { QAxObject * celluleCourante = recupererPremiereCelluleVidePremiereColonne(); for ( std::vector< std::string >::const_iterator iteInfo = informations.begin(); iteInfo != informations.end(); ++iteInfo ) { celluleCourante->dynamicCall( "SetValue(String)", iteInfo->c_str() ); celluleCourante = offsetCelluleDroite( celluleCourante ); } //const int idPremiereLigneVide = premiereLigneVide->property( "Row" ).toInt(); //std::cout << "idPremiereLigneVide: " << idPremiereLigneVide << std::endl; }
void MainWindow::test() { QAxObject* excel = new QAxObject( "Excel.Application" ); excel->dynamicCall( "SetVisible(bool)", false ); QAxObject *workbooks = excel->querySubObject( "Workbooks" ); //得到Workbooks集合的指针 //QAxObject *workbookSrc = workbooks->querySubObject( "Open(const QString&)", "F:\\QExcelConvert\\test.xls" ); QAxObject *workbookSrc = workbooks->querySubObject( "Open(const QString&)", "F:\\QExcelConvert\\test.xls" ); QAxObject *worksheet = workbookSrc->querySubObject("Worksheets(int)", 1); QAxObject * b5 = worksheet->querySubObject("Range(B7)"); QString str = b5->property("Value").toString(); qDebug()<<str; QAxObject * a5 = worksheet->querySubObject("Range(A5)"); a5->setProperty("Value", QVariant(str)); //excel.setProperty("DisplayAlerts", 0); //workbookSrc->dynamicCall("SaveAs (const QString&)", "F:\\QExcelConvert\\test2.xls"); workbookSrc->dynamicCall("Save (void)"); //excel->setProperty("DisplayAlerts", 1); workbookSrc->dynamicCall("Close (Boolean)", false); excel->dynamicCall("Quit (void)"); delete excel; }
bool Excel::setValue(int row, int col, const QString& strValue) { try { if (!excelSheet) return false; QAxObject *range = excelSheet->querySubObject("Cells(int,int)", row, col); if (!range) return false; range->dynamicCall("SetValue(const QVariant&)", QVariant(strValue)); // return true; } catch (...) { return false; } }
bool Excel::setValue(int row, int col, const QString& strValue, int nType) { try { char sCell[18]; memset(sCell, 0, 18); if (col <= 26) sprintf(sCell, " %c", 'A' + col - 1); else sprintf(sCell, "%c%c", 'A' + col / 26 - 1, 'A' + col % 26 - 1); QString cell = sCell; columnName = columnName.toUpper() > cell.toUpper() ? columnName : cell; cell = cell.trimmed() + QString::number(row); cell = cell + ":" + cell; if (!excelSheet) return false; QAxObject *range = excelSheet->querySubObject("Cells(int,int)", row, col); if (!range) return false; if (row == 1) { range->dynamicCall("SetHorizontalAlignment(const QVariant&)", QVariant(-4108)); range->dynamicCall("SetNumberFormatLocal(const QVariant&)", QVariant("@")); } else if (nType == 7 || nType == 8 || nType == 9 || nType == 11 || nType == 12 || nType == 10) //SA_dtString range->dynamicCall("SetNumberFormatLocal(const QVariant&)", QVariant("@")); if (!strValue.isNull() && !strValue.isEmpty()) range->dynamicCall("SetValue(const QVariant&)", QVariant(strValue)); delete range; return true; } catch (...) { return false; } }