qtCSV格式文件的输出

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
	}

qtCSV格式文件的输出_第1张图片

你可能感兴趣的:(qt,常用语法)