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 }
BOOL CAutoBrowser::GetWebWindowScroll(LONG *pX,LONG *pY) { BOOL bGetRes = FALSE; do { CComQIPtr<IWebBrowser> pWb(m_pWebBrowser); if (pWb == NULL) { break; } CComQIPtr<IHTMLDocument2> pDoc2; pWb->get_Document((IDispatch **)&pDoc2); if (pDoc2 == NULL) { break; } CComQIPtr<IHTMLDocument3> pDoc3(pDoc2); if (pDoc3 == NULL) { break; } CComQIPtr<IHTMLElement> pDoc3Elem; pDoc3->get_documentElement(&pDoc3Elem); if (pDoc3Elem == NULL) { break; } CComQIPtr<IHTMLElement2> pDoc3Elem2(pDoc3Elem); if(pDoc3Elem2 == NULL) { break; } if(pY) { pDoc3Elem2->get_scrollTop(pY); } if(pX) { pDoc3Elem2->get_scrollLeft(pX); } bGetRes = TRUE; } while (FALSE); return bGetRes; }
BOOL CAutoBrowser::ScrollWebWindowTo(LONG X,LONG Y) { CComQIPtr<IWebBrowser> pWb(m_pWebBrowser); if (pWb) { //IHTMLWindow2 CComQIPtr<IHTMLDocument2> pDoc2; pWb->get_Document((IDispatch **)&pDoc2); if (pDoc2) { CComQIPtr<IHTMLWindow2> pWin2; pDoc2->get_parentWindow(&pWin2); if (pWin2) { LONG CurX = 0; LONG CurY = 0; BOOL bRes = GetWebWindowScroll(&CurX,&CurY); if (bRes) { //先滚动Y轴 竖着的 if(Y > CurY) //向下滚动 { int n=0; for (int i=CurY;i<=Y;i+=120) { pWin2->scroll(CurX,i); n++; if ( n%4 == 0 ) { Sleep(GetRandValue(500,1000)); } else { Sleep(GetRandValue(50,100)); } } } else //向上滚动 { int n=0; for (int i=CurY;i>=Y;i-=120) { pWin2->scroll(CurX,i); n++; if ( n%4 == 0 ) { Sleep(GetRandValue(500,1000)); } else { Sleep(GetRandValue(50,100)); } } } Sleep(GetRandValue(500,1000)); pWin2->scroll(CurX,Y); CurY = Y; //滚动X轴 横着的 if(X > CurX) //向左滚动 { int n=0; for (int i=CurX;i<=X;i+=120) { pWin2->scroll(i,CurY); n++; if ( n%4 == 0 ) { Sleep(GetRandValue(500,1000)); } else { Sleep(GetRandValue(50,100)); } } } else //向上滚动 { int n=0; for (int i=CurX;i>=X;i-=120) { pWin2->scroll(i,CurY); n++; if ( n%4 == 0 ) { Sleep(GetRandValue(500,1000)); } else { Sleep(GetRandValue(50,100)); } } } Sleep(GetRandValue(500,1000)); pWin2->scroll(X,CurY); } else { pWin2->scroll(X,Y); } } } } return TRUE; }