关于excel读写

void ConfigerExcel::Write_Excel(QString Path, Task_Cmp &p_CmpData, \
                                 std::vector<QString> &p_freq ,\
                                 std::vector<int> &p_id)
{
    if(p_CmpData.size() == 0)
    {
        qDebug()<<"Export_Excel save failed,data size 0";
        return;
    }
    QString name = Path;
    Book *book = xlCreateBook();
    Format* format_title = book->addFormat();
    Font* font = book->addFont();
    font->setSize(15);
    format_title->setAlignH(ALIGNH_CENTER);
    format_title->setAlignV(ALIGNV_CENTER);
    format_title->setNumFormat(NUMFORMAT_TEXT);
    format_title->setBorder(BORDERSTYLE_NONE);
    format_title->setFont(font);
 
    Format* format_contex = book->addFormat();
    Font* font1 = book->addFont();
    font1->setSize(13);
    format_contex->setAlignH(ALIGNH_CENTER);
    format_contex->setAlignV(ALIGNV_CENTER);
    format_contex->setNumFormat(NUMFORMAT_GENERAL);
    format_contex->setBorder(BORDERSTYLE_THIN);
    format_contex->setFont(font1);
 
    Format* format_fre = book->addFormat();
    Font* font2 = book->addFont();
    font2->setSize(13);
    format_fre->setAlignH(ALIGNH_CENTER);
    format_fre->setAlignV(ALIGNV_CENTER);
    format_fre->setNumFormat(NUMFORMAT_TEXT);
    format_fre->setBorder(BORDERSTYLE_NONE);
    format_fre->setFont(font2);
 
    if(book)
    {
        Sheet* sheetMag = book->addSheet("幅度数据输出");
        Sheet* sheetPhase= book->addSheet("相位数据输出");
        if(sheetPhase&&sheetMag)
        {
            sheetMag->writeStr(0,0,"列-n",format_title);
            sheetMag->writeStr(0,1,"行-m",format_title);
            sheetPhase->writeStr(0,0,"列-n",format_title);
            sheetPhase->writeStr(0,1,"行-m",format_title);
 
            for(size_t i =0;i<p_id.size();++i)
            {
                int id  = p_id.at(i);
                short ls_row = 0;
                short ls_col = 0;
                TwoShortToId::instance()->IdToAddr(id,ls_row,ls_col);
 
                sheetMag->writeNum(i+1,0,ls_col,format_contex);
                sheetMag->writeNum(i+1,1,ls_row,format_contex);
 
                sheetPhase->writeNum(i+1,0,ls_col,format_contex);
                sheetPhase->writeNum(i+1,1,ls_row,format_contex);
            }
 
            int col = 2;
            for(size_t i=0;i<p_freq.size();++i)
            {
                sheetMag->setCol(col,col,12);
                sheetPhase->setCol(col,col,12);
                QString cur_freq = p_freq.at(i);
                if(p_CmpData.count(cur_freq)>0)
                {
                    QString freq = QString::number(cur_freq.toDouble()/1000000,'f',0);
                    QString buf = freq + QString("MHz");
                    sheetMag->writeStr(0,col,buf.toLocal8Bit().data(),format_fre);
                    sheetPhase->writeStr(0,col,buf.toLocal8Bit().data(),format_fre);
 
                    std::map<int,std::pair<double,double> > ls_map =  p_CmpData[cur_freq];
                    int row =1;
                    for(size_t j =0 ;j<p_id.size();++j)
                    {
                        int id = p_id.at(j);
                        if(ls_map.count(id)>0)
                        {
//                            QString magn = QString::number(ls_map[id].first,'f',3);
//                            QString phase = QString::number(ls_map[id].second,'f',3);
                            sheetMag->writeNum(row,col,ls_map[id].first,format_contex);
                            sheetPhase->writeNum(row,col,ls_map[id].second,format_contex);
                        }else
                        {
                            qDebug()<<"ConfigerExcel id not exist !";
                        }
                        ++row;
                    }
                    ++col;
                }else qDebug()<<"ConfigerExcel freq not exist !"<<cur_freq;
            }
        }
        bool ret = book->save(name.toLocal8Bit().data());
        if(ret)
        {
            // REPORT_SUCCEED;
        }/*else
            FILE_IS_OPEN;*/
        book->release();
    }
 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值