Beispiel #1
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();
    }
}
Beispiel #2
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");
    }
}
Beispiel #3
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);
}