void Dialog::processData(){// QAxObject* excel = new QAxObject( "Excel.Application", 0 );// QAxObject *workbooks = excel->querySubObject( "Workbooks" ); // вернулся нулевой указатель if(!isFNameNormal()) return; QString ffName = ui->le_DataFile->text(); updateState(QString::fromUtf8("Начинаем обработку файла: %1").arg(ffName)); qApp->processEvents(); bool useTemplAbCuant = makeTemplFiles(); bool debugThis = false; bool dontSave = false; //ui->cb_dontSave->isChecked(); ui->progressBar->setValue(0); ui->progressBar->setValue(0); updateState(QString::fromUtf8("Инициализация 'Excel.Application'")); qApp->processEvents(); QAxObject* excel = new QAxObject( "Excel.Application", 0 ); QAxBase* workbooks = excel->querySubObject( "Workbooks" ); updateState(QString::fromUtf8("Открываем '%1'").arg(ffName)); qApp->processEvents(); QAxBase* workbook = workbooks->querySubObject( "Open(const QString&)",ffName /* "C:\\Users\\LocalDev\\teste.xls" */); QAxBase* sheets = workbook->querySubObject( "Worksheets" ); QAxBase* vMainSheet = sheets->querySubObject( "Item( int )", 1 ); //qApp->setOverrideCursor( int vAllStringCntr = 0; int vAllColumnCntr = 0; QAxObject *usedRange = 0; if (vMainSheet){ usedRange = vMainSheet->querySubObject("Cells( int, int)",1,1); if (usedRange) { QAxObject *specialCell = usedRange->querySubObject("SpecialCells(int)", 11); if(specialCell){ vAllStringCntr = specialCell->property("Row").toInt(); vAllColumnCntr = specialCell->property("Column").toInt(); delete specialCell; } } } if (debugThis){ // Пока отладим //vAllColumnCntr = 8; //allColumnData; allMonth = 2; } qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); int vShCount = sheets->dynamicCall("Count()").toInt(); int vIndexColDT = 0; QString vValStr = ""; for (int colcntr = 1; colcntr <= vAllColumnCntr;colcntr++ ){ usedRange = vMainSheet->querySubObject("Cells( int, int)",1,colcntr); if (usedRange) { vValStr = usedRange->property("Value").toString(); if (vValStr == "DT"){ vIndexColDT = colcntr; } } } QString vVal2 = ""; QVariant vVal; int vValPrc; int tMons = 0; if (vShCount == 1 || useTemplAbCuant){ // Можно продолжать. for (int mns = 1; mns<=allMonth; mns++){ vValPrc = (mns*100/allMonth); qApp->processEvents(); ui->progressBar->setValue(vValPrc); clearMap(); QAxBase* workbookTo = 0; QString fNameTo = ""; QAxBase* vAddSheet = 0; //sheets->querySubObject( "Add()"); QAxBase* vSheetStat = 0; //sheets->querySubObject( "Add()"); if (useTemplAbCuant){ fNameTo = m_tmlFiles.at(mns-1); workbookTo = workbooks->querySubObject( "Open(const QString&)",fNameTo /* "C:\\Users\\LocalDev\\teste.xls" */); sheets = workbookTo->querySubObject( "Worksheets" ); vAddSheet = sheets->querySubObject( "Item( const QString& )", "Data" ); } else { vAddSheet = sheets->querySubObject( "Add()"); } int vCurRow = 0; if (vAddSheet){ if (!useTemplAbCuant) vAddSheet->dynamicCall("Name",QVariant(QString("%1").arg(mns))); // Устанавливаем значение. for(int CNTR_Str = 1; CNTR_Str<= vAllStringCntr; CNTR_Str++){ bool processRow = false; if (CNTR_Str == 1){ processRow = true; m_mapColToSubstance.clear(); } else { usedRange = vMainSheet->querySubObject("Cells( int, int)",CNTR_Str,vIndexColDT); if (usedRange) { vValStr = usedRange->property("Value").toString(); vVal2 = vValStr.mid(5,2); tMons = vVal2.toInt(); //qDebug() << "CNTR_Str"<< CNTR_Str << vValStr << vVal2 << "tMons" << tMons; if (tMons == mns){ processRow = true; } } } if (processRow){ vCurRow += 1; for(int cntCols = 1; cntCols <= vAllColumnCntr; cntCols++ ){ usedRange = vMainSheet->querySubObject("Cells( int, int)",CNTR_Str,cntCols); if (usedRange) { vVal = usedRange->property("Value"); if (CNTR_Str == 1) { m_mapColToSubstance[cntCols] = vVal.toString(); } else { if (m_mapColToSubstance.size() > 0){ if (m_mapColToSubstance.contains(cntCols)){ QString subst = m_mapColToSubstance.value(cntCols); sData* data = getContainer(subst); if (data) {// qreal valN = vVal.toDouble();// if (valN != ) QString isNanStr = vVal.toString(); if (!isNanStr.isEmpty()) data->m_vect.append(vVal.toDouble()); } } } } usedRange = vAddSheet->querySubObject("Cells( int, int)",vCurRow,cntCols); if (usedRange) usedRange->setProperty("Value", vVal); } } } } // конец сканирования листа. if (useTemplAbCuant){ vSheetStat = sheets->querySubObject( "Item( const QString& )", "Stat" ); if (vSheetStat){ // Теперь надо перекинуть это с листа Data на лист "Stat" int nPokazNameRow = 12; ///\todo продолжить тут. for (int sbstCnt = 2; sbstCnt<30; sbstCnt++){ /* Посмотрим, какие показатели у нас в в листа "Stat" в строке 12. * Найдем показатель в кеше, отсортируем и вставим. */ usedRange = vSheetStat->querySubObject("Cells( int, int)",nPokazNameRow,sbstCnt); if (usedRange) { vVal = usedRange->property("Value"); QString caption = vVal.toString(); caption = caption.trimmed(); QString substIdx = ""; if(g_dataToAbr.size()>0){ if (g_dataToAbr.contains(caption)) substIdx = g_dataToAbr.value(caption); else { qDebug() << "caption '" << caption << "'not found"; } } if (!substIdx.isEmpty()){ // Нашли... sData * dtEl = getContainer(substIdx); if(dtEl){ int idxRow = nPokazNameRow; qreal data = 0.0; dtEl->sort(); for (int dtElItemCnt = 0; dtElItemCnt<dtEl->m_vect.size(); dtElItemCnt++){ data = dtEl->m_vect.at(dtElItemCnt); idxRow = idxRow + 1; usedRange = vSheetStat->querySubObject("Cells( int, int)",idxRow,sbstCnt); if (usedRange){ bool isset = usedRange->setProperty("Value", data); vVal = usedRange->property("Value"); //qDebug() << "Set val'" << data << "' to col" << sbstCnt << "row" << idxRow << "to the Stat list"; } if (dtElItemCnt%10==0) qApp->processEvents(); } } } } } if (dontSave) { } else { workbookTo->dynamicCall("Save()"); workbookTo->dynamicCall("Close()"); } } } delete vAddSheet; } updateState(QString::fromUtf8("Обработали '%1' месяц.").arg(mns)); } } else { updateState(QString::fromUtf8("В файле '%1'' больше одного листа. Наверное обработка уже была произведена.").arg(ffName)); } excel->setProperty("DisplayAlerts", false); if (dontSave) { } else /*excel*/workbook->dynamicCall("Save()"); workbook->dynamicCall("Close()"); excel->setProperty("DisplayAlerts", true); excel->dynamicCall("Quit()");// delete shapes;// delete range;// delete sheet; delete vMainSheet; delete sheets; delete workbook; delete workbooks; excel->dynamicCall("Quit()"); delete excel; updateState(QString::fromUtf8("Обработка завершена!")); ManageDialogControls(); qApp->restoreOverrideCursor(); ui->progressBar->setValue(0);}