QFile file("c://qt_workspace//read//file.xlsx"); if (!file.open(QIODevice::ReadOnly)) return 0; QTextStream stream(&file); while(!stream.atEnd()) { mas1.append(stream.readLine()); }
cout<<mas1[0]<<mas1[1]<<mas1[2]<<mas1[3]<<mas1[4]<<mas1[5];
QString ffName = ui->le_DataFile->text(); updateState(QString::fromUtf8("Начинаем обработку файла: %1").arg(ffName)); ui->progressBar->setValue(0); QAxObject* excel = new QAxObject( "Excel.Application", 0 ); QAxBase* workbooks = excel->querySubObject( "Workbooks" ); 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 ); 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; } } for(int CNTR_Str = 1; CNTR_Str<= vAllStringCntr; CNTR_Str++){ bool processRow = false; if (CNTR_Str == 1){ for(int cntCols = 1; cntCols <= vAllColumnCntr; cntCols++ ){ usedRange = vMainSheet->querySubObject("Cells( int, int)",CNTR_Str,cntCols); if (usedRange) { vVal = usedRange->property("Value"); } } } } }
int main(int argc, char *argv[]){ QString strVal; const char* cp = "Range(B25)"; int i; QVector<float> mas; QApplication a(argc, argv); QAxWidget excel("Excel.Application"); excel.setProperty("Visible", false);//окрываю файл QAxObject *workbooks = excel.querySubObject("WorkBooks"); workbooks->dynamicCall("Open (const QString&)", "c:\\qt_projects\\read\\file1.xls"); QAxObject *workbook = excel.querySubObject("ActiveWorkBook"); QAxObject *worksheet = workbook->querySubObject("Worksheets(int)", 1); for(i=2; i<=50; i++){//считываю информацию из 3 столбца файла QAxObject* cell = worksheet->querySubObject("Cells(QVariant,QVariant)", i, 3); QVariant vv = cell->property("Value"); float ss = vv.toFloat() ; mas.append(ss); } // close the excel file excel.dynamicCall("Quit (void)"); return(0);}