Ejemplo n.º 1
0
bool Finder::rowCount(QXlsx::Document &schedule,int & lastRow)
{
    for (int row=7; row<65536; ++row)
    {
        bool abort = m_abort;
        if (abort) {
            removeCopiedFiles();
            emit finished(false);
            return false;
        }

        if(QXlsx::Cell *cell=schedule.cellAt(row, 6))
        {
            if(cell->value() == QVariant("Masa"))
            {
                lastRow = row - 2;
                break;
            }
        }

        if(m_searchCriterion == "Others") {
            if(QXlsx::Cell *cell=schedule.cellAt(row, 10))
                if(!cell->value().toString().isEmpty()){

                    QStringList list = cell->value().toString().split(" ");
                    if(list.back()!="")m_copartnerSet.insert(cell->value().toString().toLower());
                    else m_copartnerSet.insert(cell->value().toString().toLower().replace(" ",""));

                }
        }
    }
    return true;
}
Ejemplo n.º 2
0
bool Finder::checkSchedule(QXlsx::Document &schedule)
{
    QString orderDigit = schedule.cellAt(6, 2)->value().toString();
    QString drawingNr = schedule.cellAt(6, 3)->value().toString();
    QString cooperator = schedule.cellAt(6, 10)->value().toString();

    if( orderDigit.contains("L.p.") && drawingNr.contains("Nr rys.") && cooperator.contains("Kooperant") )
        return true;
    else
        return false;
}
Ejemplo n.º 3
0
void DBsearchsetting::on_seve_excel_btn_clicked()
{
    QFileDialog filepath(this);
    filepath.setAcceptMode(QFileDialog::AcceptSave);
    filepath.setNameFilter("*.xlsx");

    QStringList headeritem;
    for(int i=0;i<Setting_Query->columnCount();i++){
        headeritem.insert(i,Setting_Query->headerData(i,Qt::Horizontal).toString());
    }
    QString S_filepath;
    S_filepath = filepath.getSaveFileName(this,QString(""),QString(""),QString("*.xlsx"));
    if(S_filepath != ""){
        QXlsx::Document xlsx;
        for(int i=1;i<=Setting_Query->columnCount();i++){
            QXlsx::Format format;
            format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
            format.setPatternBackgroundColor(QColor("gray"));
            xlsx.setColumnWidth(i,20);
            xlsx.write(1,i,headeritem.at(i-1),format);
        }
        for(int i=0;i<Setting_Query->rowCount();i++){
            for(int j=0;j<Setting_Query->columnCount();j++){
            QXlsx::Format format;
            format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
            QString data =Setting_Query->index(i,j).data(0).toString();
            xlsx.write(i+2,j+1,data,format);
            }
        }
        bool saveresult;
        saveresult = xlsx.saveAs(S_filepath);
        QMessageBox messagebox;
        if(saveresult){
            messagebox.setText(tr("save ok"));
        }else {
            messagebox.setText(tr("save error"));
        }
        messagebox.exec();
    }
}
Ejemplo n.º 4
0
/*
                                                                         * 导出计算结果
                                                                         */
void MainWindow::on_dataDump_pushButton_clicked()
{
    this->on_oneResult_pushButton_clicked ();

    //QString path = QFileDialog::getExistingDirectory(this, tr("Open Directory"),"/home",QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);

    QString fileName = QFileDialog::getSaveFileName(this,
            tr("设置导出文件"),
            "",
            tr("*.xlsx"));

    if( fileName !="")
    {
        //QString fileName = path + "/计算所得指数.xlsx";

        QXlsx::Document *xlsx = new QXlsx::Document(fileName);


        int rowC = (modelST->rowCount ());
        int columnC = (modelST->columnCount ());

        xlsx->write (1,2, "年份季度");
        xlsx->write (1,3, "计算所得指标");
        xlsx->write (1,4, "指标说明");



        for (int i = 0; i < rowC; ++i) {
            for (int j = 0; j < columnC; ++j) {
                xlsx->write ((i+2),(j+1), modelST->item (i, j)->text ());
            }
        }

        if (!fileName.isEmpty()) {
            if(xlsx->save())
                QMessageBox::warning (this,"Correct","数据导出成功");
            else
                QMessageBox::warning (this,"Error","数据导出失败");
        }
    }
}
Ejemplo n.º 5
0
int main()
{
    QXlsx::Document xlsx;
    QXlsx::Format *format1 = xlsx.createFormat();
    format1->setFontColor(QColor(Qt::red));
    format1->setFontSize(15);
    format1->setHorizontalAlignment(QXlsx::Format::AlignHCenter);
    format1->setBorderStyle(QXlsx::Format::BorderDashDotDot);
    xlsx.write("A1", "Hello Qt!", format1);
    xlsx.write("B3", 12345, format1);

    QXlsx::Format *format2 = xlsx.createFormat();
    format2->setFontBold(true);
    format2->setFontUnderline(QXlsx::Format::FontUnderlineDouble);
    format2->setFillPattern(QXlsx::Format::PatternLightUp);
    xlsx.write("C5", "=44+33", format2);
    xlsx.write("D7", true, format2);

    QXlsx::Format *format3 = xlsx.createFormat();
    format3->setFontBold(true);
    format3->setFontColor(QColor(Qt::blue));
    format3->setFontSize(20);
    xlsx.write(10, 0, "Hello Row Style");
    xlsx.write(10, 5, "Blue Color");
    xlsx.setRow(10, 40, format3);

    QXlsx::Format *format4 = xlsx.createFormat();
    format4->setFontBold(true);
    format4->setFontColor(QColor(Qt::magenta));
    for (int row=20; row<40; row++)
        for (int col=8; col<15; col++)
            xlsx.write(row, col, row+col);
    xlsx.setColumn(8, 15, 5.0, format4);

    xlsx.write("A5", QDate(2013, 8, 29));

    QXlsx::Format *format6 = xlsx.createFormat();
    format6->setPatternBackgroundColor(QColor(Qt::green));
    xlsx.write("A6", "Background color: green", format6);

    xlsx.saveAs("book1.xlsx");

    return 0;
}
Ejemplo n.º 6
0
int main(int argc, char** argv)
{
    QGuiApplication(argc, argv);

    QXlsx::Document xlsx;
    xlsx.setColumn(1, 4, 20.0);

    QXlsx::Format header;
    header.setFontBold(true);
    header.setFontSize(20);

    //Custom number formats
    QStringList numFormats;
    numFormats<<"Qt #"
             <<"yyyy-mmm-dd"
            <<"$ #,##0.00"
           <<"[red]0.00";
    xlsx.write(1, 1, "Raw data", header);
    xlsx.write(1, 2, "Format", header);
    xlsx.write(1, 3, "Shown value", header);
    for (int i=0; i<numFormats.size(); ++i) {
        int row = i+2;
        xlsx.write(row, 1, 100.0);
        xlsx.write(row, 2, numFormats[i]);
        QXlsx::Format format;
        format.setNumberFormat(numFormats[i]);
        xlsx.write(row, 3, 100.0, format);
    }

    //Builtin number formats
    xlsx.addSheet();
    xlsx.setColumn(1, 4, 20.0);
    xlsx.write(1, 1, "Raw data", header);
    xlsx.write(1, 2, "Builtin Format", header);
    xlsx.write(1, 3, "Shown value", header);
    for (int i=0; i<50; ++i) {
        int row = i+2;
        int numFmt = i;
        xlsx.write(row, 1, 100.0);
        xlsx.write(row, 2, numFmt);
        QXlsx::Format format;
        format.setNumberFormatIndex(numFmt);
        xlsx.write(row, 3, 100.0, format);
    }

    xlsx.save();
    return 0;
}
Ejemplo n.º 7
0
int main()
{
    QXlsx::Document xlsx;
    QXlsx::Format format1;
    format1.setFontColor(QColor(Qt::red));
    format1.setFontSize(15);
    format1.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
    format1.setBorderStyle(QXlsx::Format::BorderDashDotDot);
    xlsx.write("A1", "Hello Qt!", format1);
    xlsx.write("B3", 12345, format1);

    QXlsx::Format format2;
    format2.setFontBold(true);
    format2.setFontUnderline(QXlsx::Format::FontUnderlineDouble);
    format2.setFillPattern(QXlsx::Format::PatternLightUp);
    xlsx.write("C5", "=44+33", format2);
    xlsx.write("D7", true, format2);

    QXlsx::Format format3;
    format3.setFontBold(true);
    format3.setFontColor(QColor(Qt::blue));
    format3.setFontSize(20);
    xlsx.write(11, 1, "Hello Row Style");
    xlsx.write(11, 6, "Blue Color");
    xlsx.setRow(11, 41, format3);

    QXlsx::Format format4;
    format4.setFontBold(true);
    format4.setFontColor(QColor(Qt::magenta));
    for (int row=21; row<=40; row++)
        for (int col=9; col<16; col++)
            xlsx.write(row, col, row+col);
    xlsx.setColumn(9, 16, 5.0, format4);

    xlsx.write("A5", QDate(2013, 8, 29));

    QXlsx::Format format6;
    format6.setPatternBackgroundColor(QColor(Qt::green));
    xlsx.write("A6", "Background color: green", format6);

    xlsx.saveAs("book1.xlsx");

    return 0;
}
Ejemplo n.º 8
0
void MainWindow::checkExcelFile(QString file_name)
{
    bool debug = false;
    QXlsx::Document * xlsx = new QXlsx::Document(file_name);
    QSqlQuery query;
    if (!xlsx->selectSheet("Check"))
    {
        return;
    }
    QXlsx::CellRange range = xlsx->dimension();
    int rowCount = range.rowCount();
//    int columnCount = range.columnCount();
    int columnCount = visible_columns.at(0);
/*
    if (check_box_check->isChecked() &&
        columnCount != visible_columns.at(0))
    {
        QMessageBox::information(this,tr(""), tr("Check columns do not fit database"));
    }
*/
    if (debug)
    {
        QMessageBox::information(this,tr("Rows * Columns"),
           QString::number(rowCount) + tr(" * ") + QString::number(columnCount));
    }
    int newCount = 0;
    int insertCount = 0;

    for (int i = 1; i <= rowCount; ++i)
    {
        QString name = xlsx->read(i, 1).toString();
        if (debug)
        {
            QMessageBox::information(this,tr("name"), name);
        }
        SearchResult result = searchCompany(name);
        if (debug)
        {
            QMessageBox::information(this,tr("Search result: "), result.information);
        }
        if (result.color != Qt::white)
        {
            for (int j = 1; j <= columnCount; ++j)
            {
                QVariant value = xlsx->read(i, j);
                if (!value.isValid())
                {
                    continue;
                }
                QXlsx::Format format = xlsx->cellAt(i, j)->format();
                format.setPatternBackgroundColor(result.color);
                xlsx->write(i, j, value, format);
            }
            // Department;
            xlsx->write(i, columnCount + 1, result.department);
            QXlsx::Format format = xlsx->cellAt(i, columnCount + 1)->format();
            format.setPatternBackgroundColor(result.color);
            xlsx->write(i, columnCount + 1, result.department, format);

            // Row(s)
            QVariant value(result.information);
            xlsx->write(i, columnCount + 2, value);
            format = xlsx->cellAt(i, columnCount + 2)->format();
            format.setPatternBackgroundColor(result.color);
            xlsx->write(i, columnCount + 2, value, format);
        }
        if ((result.color == Qt::white) // add to database
            && check_box_check->isChecked())
        {
            newCount++;
            QString q = "INSERT INTO " + table_names.at(0) + " (";
            for (int k = 1; k < column_names.at(0).size(); ++k)
            {
                q += column_names.at(0).at(k).first;
                if (k < column_names.at(0).size() - 1)
                {
                    q += ", ";
                }
                else
                {
                    q += ") VALUES(";
                }
            }
            for (int k = 1; k < column_names.at(0).size(); ++k)
            {
                q += ":" + column_names.at(0).at(k).first;
                if (k < column_names.at(0).size() - 1)
                {
                    q += ", ";
                }
                else
                {
                    q += ");";
                }
            }
            query.prepare(q);
//            qDebug() << q;
            QString name = "";
            for (int k = 1; k <= visible_columns.at(0); ++k)
            {
                QVariant value = xlsx->read(i, k);
                query.bindValue(":" + column_names.at(0).at(k).first, value);
//                qDebug() << ":" + column_names.at(0).at(k).first << " = " << value.toString();
                if (column_names.at(0).at(k).first == "Name")
                {
                    name = value.toString();
                }
            }
            QString name1 = refineString1(name);
            QString name2 = refineString2(name1);
            query.bindValue(":Name1", QVariant(name1));
            query.bindValue(":Name2", QVariant(name2));
            if (query.exec())
            {
                insertCount++;
            }
        }
    }
    xlsx->save();
    delete xlsx;
    QMessageBox::information(this,tr(""),
                             tr("Check ok: new = ") + QString::number(newCount) +
                             tr("; insert = ")      + QString::number(insertCount));
}
Ejemplo n.º 9
0
void MainWindow::readExcelFile(QString file_name)
{
    QXlsx::Document * xlsx = new QXlsx::Document(file_name);
    QSqlQuery query;
    for (int table_id = number_of_tables - 1; table_id >= 0; --table_id)
    {
        if (!xlsx->selectSheet(table_names.at(table_id)))
        {
//            qDebug() << table_names.at(table_id) << " not found";
            continue;
        }
        QXlsx::CellRange range = xlsx->dimension();

        /*
        if (range.columnCount() != visible_columns.at(table_id))
        {
//            qDebug() << table_names.at(table_id) << " size not correct";
            continue;
        }
        */

        int rowCount = range.rowCount();
        for (int i = 1; i <= rowCount; ++i)
        {
            QString q = "INSERT INTO " + table_names.at(table_id) + " (";
            for (int j = 1; j < column_names.at(table_id).size(); ++j)
            {
                q += column_names.at(table_id).at(j).first;
                if (j < column_names.at(table_id).size() - 1)
                {
                    q += ", ";
                }
                else
                {
                    q += ") VALUES(";
                }
            }
            for (int j = 1; j < column_names.at(table_id).size(); ++j)
            {
                q += ":" + column_names.at(table_id).at(j).first;
                if (j < column_names.at(table_id).size() - 1)
                {
                    q += ", ";
                }
                else
                {
                    q += ");";
                }
            }
//            qDebug() << q;
            query.prepare(q);
            QString name = "";
            for (int j = 1; j <= visible_columns.at(table_id); ++j)
            {
                QVariant value = xlsx->read(i, j);
//                qDebug() << ":" + column_names.at(table_id).at(j).first << " : " << value.toString();
                query.bindValue(":" + column_names.at(table_id).at(j).first, value);
                if (table_id == 0 && column_names.at(table_id).at(j).first == "Name")
                {
                    name = value.toString();
                }
            }
            if (table_id == 0)
            {
                QString name1 = refineString1(name);
                QString name2 = refineString2(name1);
                query.bindValue(":Name1", QVariant(name1));
//                qDebug() << ":Name1" << " : " << name1;
                query.bindValue(":Name2", QVariant(name2));
//                qDebug() << ":Name2" << " : " << name2;
            }
            query.exec();
        }
    }
    delete xlsx;
}
Ejemplo n.º 10
0
void orderWidget::genPrice()
{
    if(orderNumber->currentIndex()>-1){
        QString path = QFileDialog::getExistingDirectory(this, "Выберите папку для сохранения", "C:\\");

        QXlsx::Document xlsx;

        xlsx.write("A1", "Заказ №");
        xlsx.write("A2", "Дата:");
        xlsx.write("A4", "Фамилия:");
        xlsx.write("A5", "Имя:");
        xlsx.write("A6", "Отчество:");

        QXlsx::Format form;
        form.setHorizontalAlignment(QXlsx::Format::AlignHCenter);

        xlsx.mergeCells("B8:D8", form);
        xlsx.write("B8", "Товарные позиции:", form);
        xlsx.write("B9", "Название", form);
        xlsx.write("C9", "Количество", form);
        xlsx.write("D9", "Сумма", form);

        xlsx.setColumnWidth(1, 12);
        xlsx.setColumnWidth(2, 25);
        xlsx.setColumnWidth(3, 12);
        xlsx.setColumnWidth(4, 15);

        ordr ord = ords[orderNumber->currentIndex()];

        xlsx.write("B1", ord.orderNum);
        xlsx.write("B2", ord.orderDate);
        xlsx.write("B4", ord.userSur);
        xlsx.write("B5", ord.userName);
        xlsx.write("B6", ord.userMid);

        int i = 0;

        for (i = 0; i < ord.itms.size(); i++){
            xlsx.write(QString("B%1").arg(i+10), ord.itms.at(i).name);
            xlsx.write(QString("C%1").arg(i+10), ord.itms.at(i).count);
            xlsx.write(QString("D%1").arg(i+10), ord.itms.at(i).sum);
        }

        xlsx.write(QString("A%1").arg(i+12), "Итого:");
        xlsx.write(QString("D%1").arg(i+12), ord.orderSum);


        xlsx.saveAs(path+"\\CompSave.xlsx");
    }
}
Ejemplo n.º 11
0
void IoslotValueExporter::toExcel()
{
    QXlsx::Document xlsx;

    // Title
    QXlsx::Format format;
    format.setFontSize(18);
    format.setFontBold(true);
    format.setHorizontalAlignment(QXlsx::Format::AlignLeft);
    xlsx.write(XLSX_PROGRAM_NAME_ROW, XLSX_KEY_COL, tr("Hydroponic system configurator"), format);

    format.setFontSize(10);
    format.setFontBold(false);
    format.setHorizontalAlignment(QXlsx::Format::AlignLeft);
    xlsx.write(XLSX_VERSION_ROW, XLSX_KEY_COL, tr("Version"), format);
    format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
    xlsx.write(XLSX_VERSION_ROW, XLSX_VALUE_COL, tr("1.0"), format);

    format.setFontSize(12);
    format.setFontBold(true);
    format.setHorizontalAlignment(QXlsx::Format::AlignLeft);
    xlsx.write(XLSX_DEVICE_ADDRESS_ROW, XLSX_KEY_COL, tr("Address"), format);
    format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
    xlsx.write(XLSX_DEVICE_ADDRESS_ROW, XLSX_VALUE_COL, d_address, format);

    QVector<bool> valueEmpty(d_ioslotManager->ioslotCount(), false);

    // Table header
    format.setFontSize(12);
    format.setFontBold(true);
    format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
    format.setTopBorderStyle(QXlsx::Format::BorderThick);
    format.setBottomBorderStyle(QXlsx::Format::BorderThick);
    format.setLeftBorderStyle(QXlsx::Format::BorderThin);
    format.setRightBorderStyle(QXlsx::Format::BorderThin);

    int col = 1;
    xlsx.write(XLSX_HEADER_ROW, col, tr("Timestamp"), format);
    ++col;

    for (int num = 0; num < d_ioslotManager->ioslotCount(); ++num) {
        if (d_ioslotManager->ioslot(num)->type() == UnknownIoslotType) {
            valueEmpty[num] = true;
            continue;
        }

        const QString &name = d_ioslotManager->ioslot(num)->name();
        xlsx.write(XLSX_HEADER_ROW, col, name, format);
        ++col;
    }

    // Table content
    format.setFontSize(12);
    format.setFontBold(false);
    format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
    format.setTopBorderStyle(QXlsx::Format::BorderThin);
    format.setBottomBorderStyle(QXlsx::Format::BorderThin);
    format.setLeftBorderStyle(QXlsx::Format::BorderThin);
    format.setRightBorderStyle(QXlsx::Format::BorderThin);

    int count = d_table->recordCount(d_from, d_to);
    const int limit = 100;

    int row = 0;
    for (int offset = 0; offset < count; offset += limit) {
        QList<IoslotValueRecord> records = d_table->records(d_from, d_to, limit, offset);
        QList<IoslotValueRecord>::iterator it = records.begin();

        for (; it != records.end(); ++it, ++row) {
            IoslotValueRecord &record = *it;

            int col = 1;
            xlsx.write(XLSX_DATA_START_ROW + row, col,
                       record.timestamp().toString("yyyy-MM-dd hh:mm:ss.zzz"),
                       format);
            ++col;

            const QList<IoslotValueRecord::RecordValue> &values = record.values();
            QList<IoslotValueRecord::RecordValue>::const_iterator it2 = values.begin();

            for (int num = 0; it2 != values.end(); ++it2, ++num) {
                if (valueEmpty[num]) continue;

                const IoslotValueRecord::RecordValue &value = *it2;
                xlsx.write(XLSX_DATA_START_ROW + row, col, value.second, format);
                ++col;
            }
        }

        Q_EMIT progress(offset, count);
    }

    (void)xlsx.saveAs(d_filename);
}
Ejemplo n.º 12
0
void Finder::findCells(QXlsx::Document &schedule, QXlsx::Cell *cell, int row, QMap<QString, QColor> &colorsMap)
{
    QString currentCellNumber=0;

    if(m_searchCriterion.isEmpty()) {


        if(cell->format().patternBackgroundColor().toRgb() == colorsMap["nocolor"] && !cell->value().toString().isEmpty())
        {
            m_fileList << cell->value().toString().trimmed() + ".pdf";
            currentCellNumber = schedule.cellAt(row, 2)->value().toString();

            if(schedule.cellAt(row+1,2)->value().toString().contains(currentCellNumber)) {
                m_fileList << cell->value().toString().trimmed() + "_wykaz.pdf";
                m_fileList.swap(m_fileList.size()-1, m_fileList.size()-2);
            }

        }

        if ((cell->format().patternBackgroundColor().toRgb() == colorsMap["orange"] && !cell->value().toString().isEmpty()) ||
            (cell->format().patternBackgroundColor().toRgb() == colorsMap["orange2"] && !cell->value().toString().isEmpty()) ||
            (cell->format().patternBackgroundColor().toRgb() == colorsMap["orange3"] && !cell->value().toString().isEmpty()))
        {
            m_fileList << cell->value().toString().trimmed() + ".pdf";

        }

        if((cell->format().patternBackgroundColor().toRgb() == colorsMap["yellow"] && !cell->value().toString().isEmpty() && schedule.cellAt(row, 10)->value().toString().contains("Sigma", Qt::CaseInsensitive)) ||
          (cell->format().patternBackgroundColor().toRgb() == colorsMap["yellow2"] && !cell->value().toString().isEmpty() && schedule.cellAt(row, 10)->value().toString().contains("Sigma", Qt::CaseInsensitive)))
        {
            m_fileList << cell->value().toString().trimmed() + ".pdf";
        }
    }

    else {

        if(cell->format().patternBackgroundColor().toRgb() == colorsMap["nocolor"] &&
           !cell->value().toString().isEmpty() &&
           schedule.cellAt(row, 10)->value().toString().contains(m_searchCriterion, Qt::CaseInsensitive))
        {
            m_fileList << cell->value().toString().trimmed() + ".pdf";
            currentCellNumber = schedule.cellAt(row, 2)->value().toString();

            if(schedule.cellAt(row+1,2)->value().toString().contains(currentCellNumber)) {
                m_fileList << cell->value().toString().trimmed() + "_wykaz.pdf";
                m_fileList.swap(m_fileList.size()-1, m_fileList.size()-2);
            }

        }

        if ((cell->format().patternBackgroundColor().toRgb() == colorsMap["orange"] &&
             schedule.cellAt(row, 10)->value().toString().contains(m_searchCriterion, Qt::CaseInsensitive) &&
             !cell->value().toString().isEmpty()) ||
            (cell->format().patternBackgroundColor().toRgb() == colorsMap["orange2"] &&
             schedule.cellAt(row, 10)->value().toString().contains(m_searchCriterion, Qt::CaseInsensitive) &&
             !cell->value().toString().isEmpty()) ||
            (cell->format().patternBackgroundColor().toRgb() == colorsMap["orange3"] &&
             schedule.cellAt(row, 10)->value().toString().contains(m_searchCriterion, Qt::CaseInsensitive) &&
             !cell->value().toString().isEmpty()))
        {
            m_fileList << cell->value().toString().trimmed() + ".pdf";

        }

        if((cell->format().patternBackgroundColor().toRgb() == colorsMap["yellow"] &&
           !cell->value().toString().isEmpty() &&
           schedule.cellAt(row, 10)->value().toString().contains(m_searchCriterion, Qt::CaseInsensitive)) ||
           (cell->format().patternBackgroundColor().toRgb() == colorsMap["yellow2"] &&
           !cell->value().toString().isEmpty() &&
           schedule.cellAt(row, 10)->value().toString().contains(m_searchCriterion, Qt::CaseInsensitive)))
        {
            m_fileList << cell->value().toString().trimmed() + ".pdf";
        }
    }

}
Ejemplo n.º 13
0
DATA::Agent LiliHelper::parseAgent(const QString aPath, const QStringList aAliases, const QString aSheet)
{
    QXlsx::Document aDocument (aPath);
    DATA::Agent aAgent;

    QStringList aStringList;
    if (aSheet.length() != 0)
    {
        aStringList.append(aSheet);
    }
    else
    {
        aStringList = aDocument.sheetNames();
    }

    for (auto aSheet : aStringList)
    {
        aDocument.selectSheet(aSheet);
        QXlsx::CellRange aSheetRange (aDocument.dimension());

        QHash<QString, QDate> aRefDateMap;
        QDate aCurrentDate;
        QString aNote;
        for (int nRow = aSheetRange.firstRow(); nRow <= aSheetRange.lastRow(); ++nRow)
        {
            QVariant aCell = aDocument.read(nRow, 2);
            const bool bFirst = aCell.type() == QVariant::String && s_aWeekDays.contains(aCell.toString());

            if (bFirst)
            {
                if (aDocument.read(nRow, 19).type() == QVariant::String)
                {
                    aNote = aDocument.read(nRow, 19).toString();
                }

                QString aCellRef = QXlsx::CellReference (nRow, 9).toString();
                QVariant aDateVariant = aDocument.read(aCellRef);

                // Looking for date without reference
                if (!aCurrentDate.isValid() && aDateVariant.type() == QVariant::Date)
                {
                    aCurrentDate = aDateVariant.toDate();
                    aRefDateMap.insert(aCellRef, aCurrentDate);
                }

                // Looking for date with reference
                else if (aCurrentDate.isValid() && aDateVariant.type() == QVariant::String)
                {
                    QRegularExpression aRx;
                    QRegularExpressionMatchIterator aRxIterator;
                    aRx.setPattern("=(\\w+\\d+)\\+(\\d+)");

                    aRxIterator = aRx.globalMatch(aDateVariant.toString());

                    if (aRxIterator.hasNext())
                    {
                        QRegularExpressionMatch aMatch = aRxIterator.next();
                        QString aReferencedCell = aMatch.captured(1);
                        if (aRefDateMap.contains(aReferencedCell))
                        {
                            aCurrentDate = aRefDateMap[aReferencedCell].addDays(aMatch.captured(2).toInt());
                            aRefDateMap.insert(aCellRef, aCurrentDate);
                        }
                    }
                }

            }
            else if (aCurrentDate.isValid())
            {
                QVariant aNameVariant = aDocument.read(nRow, 1);
                if (aNameVariant.type() == QVariant::String && aAliases.contains(aNameVariant.toString()))
                {
                    int nHourHead = 2;
                    while (nHourHead <= 54)
                    {
                        QVariant aVariant = aDocument.read(nRow, nHourHead);
                        int nTempHead = nHourHead + 1;

                        if (aVariant.type() == QVariant::Double && aVariant.toInt() == 1)
                        {
                            QTime aStartTime (7, 0);
                            if (nHourHead > 2)
                            {
                                aStartTime = aStartTime.addSecs(1800 + (nHourHead - 3) * 900);
                            }
                            QTime aEndTime = aStartTime.addSecs(15 * 60);
                            aVariant = aDocument.read(nRow, nTempHead);
                            while (nTempHead <= 54 && aVariant.type() == QVariant::Double && aVariant.toInt() == 1)
                            {
                                aEndTime = aEndTime.addSecs(15 * 60);
                                ++nTempHead;
                                aVariant = aDocument.read(nRow, nTempHead);
                            }
                            aAgent.getEvents().append(DATA::CalEvent (QDateTime (aCurrentDate, aStartTime),
                                                                      QDateTime (aCurrentDate, aEndTime),
                                                                      aNote));
                        }

                        nHourHead = nTempHead;
                    }
                }
            }

        }
    }

    return aAgent;
}
Ejemplo n.º 14
0
void ClientCore::createReport()
{
    QXlsx::Document xlsx;
    xlsx.write("A1","Склад");
    xlsx.write("B1",QString("%1").arg(mCPointer->getCurrHallName()));
    xlsx.write("A2", "Название");
    xlsx.write("B2", "Инв. номер");
    xlsx.write("C2", "Категория");
    xlsx.write("D2", "Комментарий");
    xlsx.write("E2", "Количество");

    for(int i = 0; i < itemsInCurrHall.size(); i++){
        xlsx.write(QString("A%1").arg(i+3), itemsInCurrHall.at(i)->getName());
        xlsx.write(QString("B%1").arg(i+3), itemsInCurrHall.at(i)->getInvNumber());
        xlsx.write(QString("C%1").arg(i+3), itemsInCurrHall.at(i)->getGroupName());
        xlsx.write(QString("D%1").arg(i+3), itemsInCurrHall.at(i)->getComment());
        xlsx.write(QString("E%1").arg(i+3), itemsInCurrHall.at(i)->itemCount);
    }

    xlsx.saveAs(mCPointer->getCurrHallName()+".xlsx");
}
Ejemplo n.º 15
0
int main()
{
    QXlsx::Document xlsx;
    xlsx.write(0, 2, "Row:0, Col:2 ==> (C1)");

    //Set the height of the first row to 50.0(points)
    xlsx.setRow(0, 50.0);

    //Set the width of the third column to 40.0(chars)
    xlsx.setColumn(2, 3, 40.0);

    //Set style for the row 11th.
    QXlsx::Format *format1 = xlsx.createFormat();
    format1->setFontBold(true);
    format1->setFontColor(QColor(Qt::blue));
    format1->setFontSize(20);
    xlsx.write(10, 0, "Hello Row Style");
    xlsx.write(10, 5, "Blue Color");
    xlsx.setRow(10, 40, format1);

    //Set style for the col [9th, 16th)
    QXlsx::Format *format2 = xlsx.createFormat();
    format2->setFontBold(true);
    format2->setFontColor(QColor(Qt::magenta));
    for (int row=11; row<30; row++)
        for (int col=8; col<15; col++)
            xlsx.write(row, col, row+col);
    xlsx.setColumn(8, 15, 5.0, format2);

    xlsx.save();
    return 0;
}