QT_USE_NAMESPACE int main(int argc, char **argv) { CoInitialize(0); enum State { Default = 0, OutOption } state; state = Default; QByteArray outname; QByteArray object; for (int a = 1; a < argc; ++a) { QByteArray arg(argv[a]); const char first = arg[0]; switch(state) { case Default: if (first == '-' || first == '/') { arg = arg.mid(1); arg.toLower(); if (arg == "o") state = OutOption; else if (arg == "v") { qWarning("dumpdoc: Version 1.0"); return 0; } else if (arg == "h") { qWarning("dumpdoc Usage:\n\tdumpdoc object [-o <file>]" " \n\tobject : object[/subobject]*" " \n\tsubobject: property\n" " \nexample:\n\tdumpdoc Outlook.Application/Session/CurrentUser -o outlook.html"); return 0; } } else { object = arg; } break; case OutOption: outname = arg; state = Default; break; default: break; } } if (object.isEmpty()) { qWarning("dumpdoc: No object name provided.\n" " Use -h for help."); return -1; } QFile outfile; if (!outname.isEmpty()) { outfile.setFileName(QString::fromLatin1(outname.constData())); if (!outfile.open(QIODevice::WriteOnly | QIODevice::Text)) { qWarning("dumpdoc: Could not open output file '%s'", outname.data()); } } else { outfile.open(stdout, QIODevice::WriteOnly); } QTextStream out(&outfile); QByteArray subobject = object; int index = subobject.indexOf('/'); if (index != -1) subobject = subobject.left(index); QAxObject topobject(QString::fromLatin1(subobject.constData())); if (topobject.isNull()) { qWarning("dumpdoc: Could not instantiate COM object '%s'", subobject.data()); return -2; } QAxObject *axobject = &topobject; while (index != -1 && axobject) { index++; subobject = object.mid(index); if (object.indexOf('/', index) != -1) { int oldindex = index; index = object.indexOf('/', index); subobject = object.mid(oldindex, index-oldindex); } else { index = -1; } axobject = axobject->querySubObject(subobject); } if (!axobject || axobject->isNull()) { qWarning("dumpdoc: Subobject '%s' does not exist in '%s'", subobject.data(), object.data()); return -3; } QString docu = axobject->generateDocumentation(); out << docu; return 0; }
void SongsOnlineWidget::upload() { this->setCursor(Qt::WaitCursor); QAxObject *excel = NULL; QAxObject *work_books = NULL; QAxObject *work_book = NULL; excel = new QAxObject("Excel.Application"); if (excel->isNull()) {//网络中很多使用excel==NULL判断,是错误的 QMessageBox::critical(0, "错误信息", "没有找到EXCEL应用程序"); return; } excel->setProperty("Visible", false); work_books = excel->querySubObject("WorkBooks"); QString path = lineEdit_upload->text(); if(path.isEmpty()) { QMessageBox::warning(NULL, "提示", "批量上传路径不能为空,\n点击浏览选择批量上传文件。"); return; } work_books->dynamicCall("Open (const QString&)", QString(path)); QVariant title_value = excel->property("Caption"); //获取标题 qDebug()<<QString("excel title : ")<<title_value; work_book = excel->querySubObject("ActiveWorkBook"); QAxObject *work_sheets = work_book->querySubObject("WorkSheets"); //Sheets也可换用WorkSheets int sheet_count = work_sheets->property("Count").toInt(); //获取工作表数目 qDebug()<<QString("sheet count : ")<<sheet_count; int newsong_wheet_index = 0; for(int i=1; i<=sheet_count; i++) { QAxObject *work_sheet = work_book->querySubObject("Sheets(int)", i); //Sheets(int)也可换用Worksheets(int) QString work_sheet_name = work_sheet->property("Name").toString(); //获取工作表名称 QString message = QString("sheet ")+QString::number(i, 10)+ QString(" name"); if(work_sheet_name.compare("新增歌曲") == 0) { newsong_wheet_index = i; break; } qDebug()<<message<<work_sheet_name; } if(newsong_wheet_index != 0) { QAxObject *work_sheet = work_book->querySubObject("Sheets(int)", newsong_wheet_index); QAxObject *used_range = work_sheet->querySubObject("UsedRange"); QAxObject *rows = used_range->querySubObject("Rows"); QAxObject *columns = used_range->querySubObject("Columns"); int row_start = used_range->property("Row").toInt(); //获取起始行 int column_start = used_range->property("Column").toInt(); //获取起始列 int row_count = rows->property("Count").toInt(); //获取行数 int column_count = columns->property("Count").toInt(); //获取列数 for(int i=row_start+1; i<=row_count; i++) { Media media; for(int j=column_start; j<=column_count; j++) { QAxObject *cell = work_sheet->querySubObject("Cells(int,int)", i, j); QAxObject *cell_01 = work_sheet->querySubObject("Cells(int)", i); QVariant value = cell_01->property("Value"); QVariant cell_value = cell->property("Value"); //获取单元格内容 if(j == 1) media.mid = cell_value.toString(); else if(j == 2) media.serial_id = cell_value.toString(); else if(j == 3) media.name = cell_value.toString(); else if(j == 4) media.language = cell_value.toString(); else if(j == 5) media.type = cell_value.toString(); else if(j == 6) media.singer = cell_value.toString(); else if(j == 7) media.artist_sid_1 = cell_value.toString(); else if(j == 8) media.artist_sid_2 = cell_value.toString(); else if(j == 9) media.pinyin = cell_value.toString(); else if(j == 10) media.header = cell_value.toString(); else if(j == 11) media.head = cell_value.toString(); else if(j == 12) media.words = cell_value.toString(); else if(j == 13) media.path = cell_value.toString(); else if(j == 14) media.lyric = cell_value.toString(); else if(j == 15) media.original_track = cell_value.toString(); else if(j == 16) media.sound_track = cell_value.toString(); else if(j == 17) media.start_volume_1 = cell_value.toString(); else if(j == 18) media.start_volume_2 = cell_value.toString(); else if(j == 19) media.prelude = cell_value.toString(); else if(j == 20) media.effect = cell_value.toString(); else if(j == 21) media.version = cell_value.toString(); else if(j == 22) media.create_time = cell_value.toString(); else if(j == 23) media.stars = cell_value.toString(); else if(j == 24) media.hot = cell_value.toString(); else if(j == 25) media.count = cell_value.toString(); else if(j == 26) media.enabled = cell_value.toString(); else if(j == 27) media.black = cell_value.toString(); else if(j == 28) media.match = cell_value.toString(); else if(j == 29) media.update_time = cell_value.toString(); else if(j == 30) media.resolution = cell_value.toString(); else if(j == 31) media.quality = cell_value.toString(); else if(j == 32) media.source = cell_value.toString(); else if(j == 33) media.rhythm = cell_value.toString(); else if(j == 34) media.pitch = cell_value.toString(); else if(j == 35) media.info = cell_value.toString(); } tempSave(media); } } excel->dynamicCall("Quit (void)"); this->setCursor(Qt::ArrowCursor); }