Пример #1
0
int QEXCEL::getUsedRowsCount()
{
    QAxObject *usedRange = sheet->querySubObject("UsedRange");
    int topRow = usedRange->property("Row").toInt();
    QAxObject *rows = usedRange->querySubObject("Rows");
    int bottomRow = topRow + rows->property("Count").toInt() - 1;
    return bottomRow;
}
Пример #2
0
void QEXCEL::getUsedRange(int *topLeftRow, int *topLeftColumn, int *bottomRightRow, int *bottomRightColumn)
{
    QAxObject *usedRange = sheet->querySubObject("UsedRange");
    *topLeftRow = usedRange->property("Row").toInt();
    *topLeftColumn = usedRange->property("Column").toInt();

    QAxObject *rows = usedRange->querySubObject("Rows");
    *bottomRightRow = *topLeftRow + rows->property("Count").toInt() - 1;

    QAxObject *columns = usedRange->querySubObject("Columns");
    *bottomRightColumn = *topLeftColumn + columns->property("Count").toInt() - 1;
}
Пример #3
0
QVariantList Excel::getAll(int *rows, int *cols)
{
    QVariant result;
    char sCell[18];
    try {
        getRowsCols(rows, cols);

        memset(sCell, 0, 18);
        if (*cols <= 26)
            sprintf(sCell, "%c", 'A' + *cols - 1);
        else
            sprintf(sCell, "%c%c", 'A' + *cols / 26 - 1, 'A' + *cols % 26 - 1);

        QString cell = sCell;

        cell = cell.trimmed() + QString::number(*rows);
        QString srange = "Range(\"A1\",\"" + cell + "\")";
        if (excelSheet) {
            QAxObject *range = excelSheet->querySubObject(srange.toLocal8Bit());
            if (range) {
                result =  range->property("Value");
                delete range;
            }
        }
    } catch (...) {}
    QVariantList list = qVariantValue<QVariantList>(result);

    return list;
}
Пример #4
0
QString QExcel::CellValue(int x, int y){

    if( x < 1 || y < 1 || _sheet == NULL)
        return NULL;

    QAxObject* cell = _sheet->querySubObject("Cells(int,int)", y, x);
    QString ret = cell->property("Value").toString();
    return ret;
}
Пример #5
0
QString QExcel::CellValue(int sheetIdx, int x, int y){

    if( sheetIdx < 1 || x < 1 || y < 1)
        return NULL;

    QAxObject* sheet = _sheets->querySubObject( "Item( int )", sheetIdx );
    QAxObject* cell = sheet->querySubObject("Cells(int,int)", y, x);
    QString ret = cell->property("Value").toString();
    return ret;
}
Пример #6
0
void Excel::getRowsCols(int *rows, int *cols)
{
    try {
        if (excelSheet) {
            QAxObject *ur = excelSheet->querySubObject("UsedRange()");
            if (ur) {
                QAxObject *cs = ur->querySubObject("columns()");
                if (cs) {
                    *cols = cs->property("Count").toInt();
                }

                QAxObject *rs = ur->querySubObject("Rows()");
                if (rs) {
                    *rows = rs->property("Count").toInt();
                }
            }
        }
    } catch (...) {

    }
}
Пример #7
0
QString Excel::sheetName(int index)
{
    try {
        if (!excelSheets)
            return QString();
        QAxObject *s = excelSheets->querySubObject("Item(int index)", index);
        if (s) {
            return s->property("Name").toString();

        }
    } catch (...) {}
    return QString();
}
void
CSELECT_EXCEL_TAB::
selectWorksheetTab(const int intCount)
{
    m_intCount = intCount;
    QVBoxLayout *vbox = new QVBoxLayout;
    QAxObject * worksheet = new QAxObject;
    for (int i = 1; i <= m_intCount; i++)
    {
        worksheet = m_workbook->querySubObject("Worksheets(int)", i);
        QString tabName = worksheet->property("Name").toString();
        // do not include 'change log' tab
        if ( !tabName.contains("change log") &&
             !tabName.contains("Change log") &&
             !tabName.contains("Change Log") &&
             !tabName.contains("change log") )
        {
            QRadioButton *button = new QRadioButton(worksheet->property("Name").toString());
            vbox->addWidget(button);    // add button widget
            vbox->addStretch(1);        // fit in the area
            connect(button, SIGNAL(clicked(bool)), this, SLOT(buttonSelected(bool)));   // when radio button clicked
        }
    }
Пример #9
0
QVariant Excel::value(int row, int col)
{
    QVariant vValue;
    try {
        if (!excelSheet)
            return QVariant();
        QAxObject *range = excelSheet->querySubObject("Cells(int,int)", row, col);
        if (!range)
            return QVariant();

        vValue = range->property("Value2");
        delete range;

    } catch (...) {}
    return vValue;
}
Пример #10
0
QVariant QEXCEL::getCellValue(int row, int column)
{
    QAxObject *range = sheet->querySubObject("Cells(int,int)", row, column);
    return range->property("Value");
}
void SavingSettingsTabView::saveToDocFile()
{
    fillResultStructure();
    if (m_dbTable.count() > 0) {

        QString file = createDocFile();

        if (file.isEmpty()) {
            QMessageBox::warning(0, "Внимание", "Вы не выбрали файл для выгрузки документа.");
            return;
        }

        m_wordApp = new QAxObject("Word.Application",this);
        m_wordDoc = m_wordApp->querySubObject("Documents()");
        m_wordDoc->dynamicCall("Open(QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant)", file, false, false, false, "", "", false);  //querySubObject("Add()");
        m_wordApp->setProperty("Visible", true);

        //Get active document.
        QAxObject* pActiveDocument = m_wordApp->querySubObject("ActiveDocument()");

        //Get selection.
        QAxObject *pSelection = m_wordApp->querySubObject("ActiveDocument")->querySubObject("ActiveWindow")->querySubObject("Selection");

        // создание таблицы
        QAxObject* pTables = pActiveDocument->querySubObject("Tables()");
        int commonRowCount = (m_dbTable.count())*7 + (m_answerInfo.count())*4;
        QAxObject* pNewTable = pTables->querySubObject("Add(Id, testname, firstname, secondName, surname, groupname, scorevalue, maxvalue, testtime)", pSelection->property("Range"), commonRowCount, 2, 1, 1);

        //Resize table width to whole page width.
        pNewTable->setProperty("PreferredWidthType", "wdPreferredWidthPercent");
        pNewTable->setProperty("PreferredWidth", 110);


        //Align table to center.
        pNewTable->querySubObject("Rows()")->setProperty("Alignment", "wdAlignRowCenter");

        //Iterate found records.
        QAxObject *pCell = NULL, *pCellRange = NULL, *textFont = NULL;
        int table_row = 1;

        for (int row = 0; row < m_dbTable.count(); row++) {
            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row, 1);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", "НАЗВАНИЕ ТЕСТА");
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row, 2);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", m_dbTable.at(row).testName);
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 1, 1);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", "ФИО");
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 1, 2);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", m_dbTable.at(row).surname
                                    + " " + m_dbTable.at(row).firstName.at(0)
                                    + ". " + m_dbTable.at(row).secondName.at(0) + ".");
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 2, 1);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", "ВРЕМЯ");
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 2, 2);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", m_dbTable.at(row).time);
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 3, 1);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", "ПОЛУЧЕННЫЙ БАЛЛ");
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 3, 2);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", m_dbTable.at(row).score);
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 4, 1);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", "ВОЗМОЖНЫЙ МАКСИМУМ");
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 4, 2);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", m_dbTable.at(row).maxPosibleScore);
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 5, 1);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", "ГРУППА");
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 5, 2);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", m_dbTable.at(row).group);
            textFont = pCellRange->querySubObject("Font");
            textFont->setProperty("Bold", true);

            table_row += 6;

            for (int i = 0; i < m_answerInfo.count(); i++) {
                if (m_dbTable.at(row).id == m_answerInfo.at(i).id) {
                    pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row, 1);
                    pCellRange = pCell->querySubObject("Range()");
                    pCellRange->dynamicCall("InsertAfter(Text)", "ВОПРОС");

                    pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row, 2);
                    pCellRange = pCell->querySubObject("Range()");
                    pCellRange->dynamicCall("InsertAfter(Text)", m_answerInfo.at(i).statement);

                    pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 1, 1);
                    pCellRange = pCell->querySubObject("Range()");
                    pCellRange->dynamicCall("InsertAfter(Text)", "ВЫБРАННЫЙ ВАРИАНТ");

                    pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 1, 2);
                    pCellRange = pCell->querySubObject("Range()");
                    pCellRange->dynamicCall("InsertAfter(Text)", m_answerInfo.at(i).chosenAnswer);

                    pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 2, 1);
                    pCellRange = pCell->querySubObject("Range()");
                    pCellRange->dynamicCall("InsertAfter(Text)", "ВЕРНЫЙ ВАРИАНТ");

                    pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 2, 2);
                    pCellRange = pCell->querySubObject("Range()");

                    if (m_answerInfo.at(i).isCorrectAnswer  == 1) {
                        pCellRange->dynamicCall("InsertAfter(Text)", "Верный ответ");
                    } else {
                        pCellRange->dynamicCall("InsertAfter(Text)", "Неверный ответ");
                    }

                    pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 3, 1);
                    pCellRange = pCell->querySubObject("Range()");
                    pCellRange->dynamicCall("InsertAfter(Text)", "УВЕРЕННОСТЬ");

                    pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row + 3, 2);
                    pCellRange = pCell->querySubObject("Range()");

                    if (m_answerInfo.at(i).assurance > 0) {
                        pCellRange->dynamicCall("InsertAfter(Text)", "Уверен");
                    } else if (m_answerInfo.at(i).assurance == 0) {
                        pCellRange->dynamicCall("InsertAfter(Text)", "Не уверен");
                    } else if (m_answerInfo.at(i).assurance == -1) {
                        pCellRange->dynamicCall("InsertAfter(Text)", "Не используется");
                    }

                    table_row += 4;
                }
            }

            //empty line
            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row, 1);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", "");

            pCell = pNewTable->querySubObject("Cell(Row, Column)", table_row, 2);
            pCellRange = pCell->querySubObject("Range()");
            pCellRange->dynamicCall("InsertAfter(Text)", "");
            //empty line
            table_row++;
        }
    } else {
        QMessageBox::warning(0, "Внимание", "В выбранной Вами базе нет данных.");
    }
}
    [id(1)] BSTR text;
    [id(2)] IFontDisp *font;

methods:
    [id(6)] void showColumn([in] int i);
    [id(3)] bool addColumn([in] BSTR t);
    [id(4)] int fillList([in, out] SAFEARRAY(VARIANT) *list);
    [id(5)] IDispatch *item([in] int i);
};
//! [4]


//! [5]
QAxObject object("<CLSID>");

QString text = object.property("text").toString();
object.setProperty("font", QFont("Times New Roman", 12));

connect(this, SIGNAL(clicked(int)), &object, SLOT(showColumn(int)));
bool ok = object.dynamicCall("addColumn(const QString&)", "Column 1").toBool();

QList<QVariant> varlist;
QList<QVariant> parameters;
parameters << QVariant(varlist);
int n = object.dynamicCall("fillList(QList<QVariant>&)", parameters).toInt();

QAxObject *item = object.querySubItem("item(int)", 5);
//! [5]


//! [6]
Пример #13
0
void PrepodRez::on_pushButton_5_clicked()
{
    QString fio;
    QSqlQueryModel q;
    QString ss = QString("SELECT \"FIO\" FROM \"Users\" WHERE \"id\"='%1'").arg(qq);
    q.setQuery(ss);
    fio = q.record(0).value(0).toString();

    QAxObject *word = new QAxObject("Word.Application", this);
        QAxObject *documents = word->querySubObject("Documents"); //получаем коллекцию документов
        QAxObject *document = documents->querySubObject("Add()"); //добавляем свой документ в коллекцию
        word->setProperty("Visible", true);


        QAxObject* ActiveDocument = word->querySubObject("ActiveDocument()");
            QAxObject* Range = ActiveDocument->querySubObject("Range()");
            Range->querySubObject("InsertAfter(Text)",QString("Отчет \n\r по результатам тестирования "
                                                              "студента: %1 \n\r Ведущая рука: \n"
                                                              "%2 \n"
                                                              "%4 \n"
                                                              "%6 \n"
                                                              "%8 \n"
                                                              "%9 \n "
                                                              "%10 \n"
                                                              "%3   %5   %7"
                                                              ""
                                                              "\n\r Не ведущая рука: \n"
                                                              "%11 \n"
                                                              "%12 \n"
                                                              "%13 \n"
                                                              "%14 \n"
                                                              "%15 \n "
                                                              "%16 \n"
                                                              "%17   %18   %19 \n\r"
                                                              "%20").arg(fio).arg(ui->label_8->text())
                                  .arg(ui->label_17->text())
                                  .arg(ui->label_9->text())
                                  .arg(ui->label_18->text())
                                  .arg(ui->label_10->text())
                                  .arg(ui->label_19->text())
                                  .arg(ui->label_11->text()).
                                  arg(ui->label_12->text())
                                  .arg(ui->label_13->text())
                                       .arg(ui->label_21->text())
                                       .arg(ui->label_23->text())
                                       .arg(ui->label_25->text())
                                       .arg(ui->label_27->text())
                                       .arg(ui->label_29->text())
                                       .arg(ui->label_31->text())
                                       .arg(ui->label_33->text())
                                       .arg(ui->label_35->text())
                                       .arg(ui->label_37->text())
                                       .arg(ui->label_38->text()));

            QAxObject *shrift = Range->querySubObject("Font");
                QString lol = shrift->property("Name").toString();
                shrift->setProperty("Size", 14); //задаем размер шрифта
            QTextCodec *codec = QTextCodec::codecForName("CP-1251");
                              QTextCodec::setCodecForLocale(codec);

}
/**
  *@brief 打开sXlsFile指定的excel报表
  *@return true : 打开成功
  *        false: 打开失败
  */
bool ExcelEngine::Open(UINT nSheet, bool visible)
{

    if ( bIsOpen )
    {
        //return bIsOpen;
        Close();
    }

    nCurrSheet = nSheet;
    bIsVisible = visible;

    if ( NULL == pExcel )
    {
        pExcel = new QAxObject("Excel.Application");
        if ( pExcel )
        {
            bIsValid = true;
        }
        else
        {
            bIsValid = false;
            bIsOpen  = false;
            return bIsOpen;
        }

        pExcel->dynamicCall("SetVisible(bool)", bIsVisible);
    }

    if ( !bIsValid )
    {
        bIsOpen  = false;
        return bIsOpen;
    }

    if ( sXlsFile.isEmpty() )
    {
        bIsOpen  = false;
        return bIsOpen;
    }

    /*如果指向的文件不存在,则需要新建一个*/
    qDebug() << sXlsFile;
    QFile f(sXlsFile);
    if (!f.exists())
    {
        bIsANewFile = true;
    }
    else
    {
        bIsANewFile = false;
    }

    if (!bIsANewFile)
    {
        pWorkbooks = pExcel->querySubObject("WorkBooks"); //获取工作簿
        // @author 范翔 不装Office会有空指针错误[注释]
        pWorkbook = pWorkbooks->querySubObject("Open(QString, QVariant)",sXlsFile,QVariant(0)); //打开xls对应的工作簿
    }
    else
    {
        pWorkbooks = pExcel->querySubObject("WorkBooks");     //获取工作簿
        pWorkbooks->dynamicCall("Add");                       //添加一个新的工作薄
        pWorkbook  = pExcel->querySubObject("ActiveWorkBook"); //新建一个xls
    }

    pWorksheet = pWorkbook->querySubObject("WorkSheets(int)", nCurrSheet);//打开第一个sheet

    //至此已打开,开始获取相应属性
    QAxObject *usedrange = pWorksheet->querySubObject("UsedRange");//获取该sheet的使用范围对象
    QAxObject *rows = usedrange->querySubObject("Rows");
    QAxObject *columns = usedrange->querySubObject("Columns");

    //因为excel可以从任意行列填数据而不一定是从0,0开始,因此要获取首行列下标
    nStartRow    = usedrange->property("Row").toInt();    //第一行的起始位置
    nStartColumn = usedrange->property("Column").toInt(); //第一列的起始位置

    nRowCount    = rows->property("Count").toInt();       //获取行数
    nColumnCount = columns->property("Count").toInt();    //获取列数

    bIsOpen  = true;
    return bIsOpen;
}
Пример #15
0
/**
  *@brief 打开sXlsFile指定的excel报表
  *@return true : 打开成功
  *        false: 打开失败
  */
bool ExcelEngine::open(UINT nSheet, bool visible)
{
    if ( bIsOpen )
    {
        //return bIsOpen;
        close();
    }

    if ( NULL == pExcel )
    {
        pExcel = new QAxObject("Excel.Application");
        if ( pExcel )
        {
            bIsValid = true;
        }
        else
        {
            bIsValid = false;
            bIsOpen  = false;
            return bIsOpen;
        }

        pExcel->dynamicCall("SetVisible(bool)", bIsVisible);
    }

    if ( !bIsValid )
    {
        bIsOpen  = false;
        return bIsOpen;
    }

    if ( sXlsFile.isEmpty() )
    {
        bIsOpen  = false;
        return bIsOpen;
    }


    bool ok = createXlsFile(sXlsFile);
    if ( !ok )
    {
        bIsOpen  = false;
        return bIsOpen;
    }

    nCurrSheet = nSheet;
    bIsVisible = visible;

    pWorkbooks = pExcel->querySubObject("WorkBooks"); //获取工作簿
    pWorkbook = pWorkbooks->querySubObject("Open(QString, QVariant)",sXlsFile,QVariant(0)); //打开xls对应的工作簿
    pWorksheet = pWorkbook->querySubObject("WorkSheets(int)", nCurrSheet);//打开第一个sheet

    //至此已打开,开始获取相应属性
    QAxObject *usedrange = pWorksheet->querySubObject("UsedRange");//获取该sheet的使用范围对象
    QAxObject *rows = usedrange->querySubObject("Rows");
    QAxObject *columns = usedrange->querySubObject("Columns");

    //因为excel可以从任意行列填数据而不一定是从0,0开始,因此要获取首行列下标
    nStartRow    = usedrange->property("Row").toInt();    //第一行的起始位置
    nStartColumn = usedrange->property("Column").toInt(); //第一列的起始位置

    nRowCount    = rows->property("Count").toInt();       //获取行数
    nColumnCount = columns->property("Count").toInt();    //获取列数

    bIsOpen  = true;
    return bIsOpen;
}
Пример #16
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);
}
Пример #17
0
bool MainWindow::writeSalary()
{
    QString tagFilePath = ui->lineEdit_3->text();

    if(tagFilePath.isEmpty() == true)
    {
        ui->textEdit->append(tr("2 zhaobudao"));
        return false;
    }

    //Excel应用程序包括一系列的workbooks,每个workbook又由多个sheets组成。

    QString nameStart = ui->nameEdit2->text();
    QString salaryStart = ui->salaryEdit2->text();

    if(nameStart.right(1) != salaryStart.right(1))
    {
        ui->textEdit->append(tr("qishi weizhi buyiyang"));
        return false;
    }

    QString nameChar = nameStart.left(1);
    QString salaryChar = salaryStart.left(1);
    bool isOk = false;
    int index = nameStart.right(1).toInt(&isOk);

    if(isOk == false)
    {
        ui->textEdit->append(tr("youwenti"));
        return false;
    }

    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&)", tagFilePath );
    QAxObject *worksheet = workbookSrc->querySubObject("Worksheets(int)", ui->spinBox2->value());

    QMap<QString, int> mapHelp;

    int totalCount = m_map.count();
    bool result = true;
    while(1)
    {
        QString namePos = QString("Range(%1%2)").arg(nameChar).arg(index);
        QAxObject* nameAx = worksheet->querySubObject(namePos.toStdString().c_str());
        QString name = nameAx->property("Value").toString().trimmed();

        QString salaryPos = QString("Range(%1%2)").arg(salaryChar).arg(index);
        QAxObject* salaryAx = worksheet->querySubObject(salaryPos.toStdString().c_str());

        if(name.isEmpty() == true)
        {
            break;
        }

        if(mapHelp.contains(name) == true)
        {
            result = false;
            ui->textEdit->append(QString("2 mizichongfu %1").arg(mapHelp.value(name)));
            break;
        }

        if( m_map.contains(name) )
        {
            salaryAx->setProperty("Value", m_map.value(name));
            m_map.remove(name);
            ui->textEdit->append(QString("%1 %2 %3 OK").arg(index).arg(name).arg(m_map.value(name)));
        }
        else
        {
            salaryAx->clear();
        }

        mapHelp.insert(name, index);
        index++;
    }

    if(result == true)
    {
        int nowCount = m_map.count();
        ui->textEdit->append(QString("wancheng %1/%2").arg(totalCount - nowCount).arg(totalCount));

        if(nowCount > 0)
        {
            QList<QString> keys = m_map.keys();
            for(int i = 0; i < nowCount; ++i)
            {
                int j = index + 5 + i;
                QString namePos = QString("Range(%1%2)").arg(nameChar).arg(j);
                QAxObject* nameAx = worksheet->querySubObject(namePos.toStdString().c_str());
                nameAx->setProperty("Value", keys.at(i));

                QString salaryPos = QString("Range(%1%2)").arg(salaryChar).arg(j);
                QAxObject* salaryAx = worksheet->querySubObject(salaryPos.toStdString().c_str());
                salaryAx->setProperty("Value", m_map.value(keys.at(i)));
            }
        }
    }

    workbookSrc->dynamicCall("Save (void)");
    workbookSrc->dynamicCall("Close (Boolean)", false);
    excel->dynamicCall("Quit (void)");
    delete excel;
    return result;
}
Пример #18
0
bool MainWindow::readSalary()
{
    m_map.clear();
    m_mapHelp.clear();
    QString srcFilePath = ui->lineEdit_1->text();

    if(srcFilePath.isEmpty() == true)
    {
        ui->textEdit->append(tr("1 zhaobudao"));
        return false;
    }

    //Excel应用程序包括一系列的workbooks,每个workbook又由多个sheets组成。

    QString nameStart = ui->nameEdit1->text();
    QString salaryStart = ui->salaryEdit1->text();

    if(nameStart.right(1) != salaryStart.right(1))
    {
        ui->textEdit->append(tr("qishi weizhi buyiyang"));
        return false;
    }

    QString nameChar = nameStart.left(1);
    QString salaryChar = salaryStart.left(1);
    bool isOk = false;
    int index = nameStart.right(1).toInt(&isOk);

    if(isOk == false)
    {
        ui->textEdit->append(tr("you wenti"));
        return false;
    }

    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&)", srcFilePath );
    QAxObject *worksheet = workbookSrc->querySubObject("Worksheets(int)", ui->spinBox->value());

    bool result = true;
    while(1)
    {
        QString namePos = QString("Range(%1%2)").arg(nameChar).arg(index);
        QString salaryPos = QString("Range(%1%2)").arg(salaryChar).arg(index);

        QAxObject* nameAx = worksheet->querySubObject(namePos.toStdString().c_str());
        QAxObject* salaryAx = worksheet->querySubObject(salaryPos.toStdString().c_str());

        QString name = nameAx->property("Value").toString().trimmed();
        QString salary = salaryAx->property("Value").toString();

        if(name.isEmpty() && salary.isEmpty() )
        {
            break;
        }

        ui->textEdit->append(QString("%1 %2 %3").arg(index).arg(name).arg(salary));

        if(m_map.contains(name) == true)
        {
            ui->textEdit->append(QString("same name with line %1.").arg(m_mapHelp.value(name)));
            result = false;
            break;
        }

        m_map.insert(name, salary);
        m_mapHelp.insert(name, index);
        index++;
    }

    workbookSrc->dynamicCall("Close (Boolean)", false);
    excel->dynamicCall("Quit (void)");
    delete excel;
    return result;
}
Пример #19
0
QString QEXCEL::getSheetName(int sheetIndex)
{
    QAxObject * a = sheets->querySubObject("Item(int)", sheetIndex);
    return a->property("Name").toString();
}