Ejemplo n.º 1
0
/*!
 * \overload
 * Try to open an existing xlsx document named \a name.
 * The \a parent argument is passed to QObject's constructor.
 */
Document::Document(const QString &name, QObject *parent) :
    QObject(parent), d_ptr(new DocumentPrivate(this))
{
    d_ptr->packageName = name;
    if (QFile::exists(name)) {
        QFile xlsx(name);
        if (xlsx.open(QFile::ReadOnly))
            d_ptr->loadPackage(&xlsx);
    }
    d_ptr->init();
}
Ejemplo n.º 2
0
void FoodItem::setFoodItemValue() {
    QXlsx::Document xlsx("FoodList.xlsx");
    for (int column = 3; column < 3 + _factsCount; ++column)
        if (QXlsx::Cell *cell = xlsx.cellAt(_rowId, column))
            _foodItemValue.push_back(cell->value().toInt());
}
Ejemplo n.º 3
0
//开始生成
void MainWindow::on_pushButton_start_clicked()
{
    ui->textBrowser_print->clear();

     qDebug()<< "22222222";
    // QXlsx::Document xlsx;
     QXlsx::Document xlsx(excel_path_file);

     qDebug()<< "..........ui->comboBox_sheet->currentText()..................:" << ui->comboBox_sheet->currentText();
    xlsx.selectSheet(ui->comboBox_sheet->currentText());
   // xlsx_tmp.selectSheet(arg1);
    QStringList sheetname = xlsx.sheetNames();
    QString www = xlsx.read("C1").toString();
    qDebug()<< "xx:" << www ;
    qDebug()<< "sheetname:" << sheetname ;




    //获取当前文件路径
    QString path;
    QDir dir;
    path=dir.currentPath(); //path为QString类型
    qDebug()<< path;
    QString path_dir = path+"/生成文件/" + ui->comboBox_sheet->currentText();
    if(!dir.exists(path_dir))
    {
      //dir.mkdir(path_dir); //上层目录不存在时,创建会失败。比如创建“c:\\test\test”
                            //如果test不存在,那test也创建不了。目录已经存在时会返回false。
      dir.mkpath(path_dir);//上层目录不存,自动一起创建。目录已经存在时会返回true。
      qDebug()<<"mkdir dir:" <<path_dir;
    }

    //创建xx.txt文件
    QString sheet_name =  path_dir + "/" + ui->comboBox_sheet->currentText() + ".txt"; //表名 例:menu.txt
    qDebug()<<"sheet_name:"<<sheet_name;
    QFile file(sheet_name);
    if(!file.open((QIODevice::WriteOnly)))
    {
        file.close();
        return;
    }

    //打开txt文件
    if(!file.open(QIODevice::WriteOnly))
    {
        //qDebug()<<"Can't open the file!"<<endl;
    }
    QTextStream stream(&file);
    stream.setCodec("UTF-8");
    QString line_in;
    if(ui->textEdit_1->toPlainText().isEmpty() == false) //段首 不为空
    {
        QString textEdit_1 = ui->textEdit_1->toPlainText();
        stream<< textEdit_1 << endl;
    }



    QString hang_shou = ui->textEdit_2->toPlainText();
   // qDebug() << "hang_shou:" << hang_shou;

    QString hang_wei = ui->textEdit_3->toPlainText();
   // qDebug() << "hang_wei:" << hang_wei;
    int lie_no = ui->comboBox_hang_value->currentIndex() + 1;
   // qDebug() << "lie_no:" << lie_no;

    ui->textBrowser_print->append("正在生成......" );
    qDebug() << "sheet_row..................:" << sheet_row  << "  ...........:"<< sheet_col;
    for (int row=2; row <= sheet_row; ++row)//hang
    {
        if (QXlsx::Cell *cell=xlsx.cellAt(row, lie_no))
        {
            qDebug()<<cell->value();
            QString cell_vlue =  cell->value().toString();
            line_in =  hang_shou + cell_vlue + hang_wei ;
        }
       // qDebug() << "line_in:" << line_in;
        stream<< line_in << endl;


        // int load = row/800;
         //QString s = QString("%1").arg(load);
        // QString load_str = "已完成:" + s + "%";
        // ui->textBrowser_log->append(load_str);

    }


    if(ui->textEdit_4->toPlainText().isEmpty() == false) //段尾 不为空
    {
        QString textEdit_4 = ui->textEdit_4->toPlainText();
        stream<< textEdit_4 << endl;
    }

    ui->textBrowser_print->append("生成 ...ok" );
    ui->textBrowser_print->append("\n\n生成的文件在软件的同目录下!" );



}