qtCSV格式檔案的輸出
阿新 • • 發佈:2018-12-21
CSV格式的檔案 其實就是我們常用的表格文件 傳入資料時,每個資料用英文","隔開,隔開代表兩個單元格,如果不加入“\n”,就會在第一行一直寫入。
QString fileNameCSV = QFileDialog::getSaveFileName(this, tr("Select Save Location"), QApplication::applicationDirPath(), tr("CSV Files (*.csv)")); if (!fileNameCSV.isNull()) { QFile *fileCSV = new QFile(fileNameCSV); if (fileCSV->open(QIODevice::WriteOnly)) { QString fileCSVHeader = tr("Sampling point time,") + tr("Relative altitude,") + tr("absolute altitude,") + tr("latitude,") + tr("longitude,") + tr("temperature,") + tr("humidity,") + tr("CO,") + tr("SO2,") + tr("NO2,") + tr("O3,") + tr("CO2,") + tr("PM1,") + tr("PM25,") + tr("PM10\n"); fileCSV->write(fileCSVHeader.toLocal8Bit().data()); fileCSV->close(); } } else { //cancel }