返回顶部

收藏

用Qt把数据写入Excel 中

更多

cpp代码

QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
        "",
        tr("file ( *.CSV)"));
if(fileName == "")
    return;

QTextCodec *code;
code = QTextCodec::codecForName("gb18030");

std::string strbuffer = code->fromUnicode(fileName).data();
FILE *fileWrite = fopen( strbuffer.c_str(),"w");
QString strFemale = "Female Count";
QString strMale = "Male Count";
QString strPatientCount = "Patient Count";
QString str ="\n";
std::string strCountbuffer = code->fromUnicode(strFemale+","+
    strMale+","+strPatientCount+str+QString().setNum(femaleCount)+","+
    QString().setNum(maleCount)+","+QString().setNum(patientCount)).data();
QFile file;
file.open(fileWrite, QIODevice::WriteOnly);
file.write(strCountbuffer.c_str(), qstrlen(strCountbuffer.c_str()));        
file.close(); 

标签:Excel,QFile,QTextCodec,QT

收藏

0人收藏

支持

0

反对

0

发表评论