MFC 数据保存为CSV格式(xlsx)

//相关变量参考读取参数配置章节
void SaveCsv()
{
	memset(CurrentWorkPath, 0, sizeof(CurrentWorkPath));
	GetModuleFileName(0, CurrentWorkPath, MAX_PATH);
	(_tcsrchr(CurrentWorkPath, _T('\\')))[1] = 0;//删除文件名,只获得路径
	CString Path = CurrentWorkPath;
	CTime time = CTime::GetCurrentTime();
	CString m_strTime = time.Format("%Y%m%d_%H%M%S");
	Path += "samsung_rib.csv";
	//CFile mFile(Path, CFile::modeWrite|CFile::modeCreate);
	CStdioFile mFile;
	CString str;
	static unsigned long LidarNo=0;
	static bool isGetLidarNo =0;
	if(-1==GetFileAttributes(Path))
	{
		mFile.Open(Path,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate);
		str.Format(_T("LidarNo.,")
				   _T("0°Offset Angle,")
				   _T("(0)Angle of Distortion Area,")
				   _T("(1)Angle of Distortion Area,")
				   _T("(2)Angle of Distortion Area,")
				   _T("(3)Angle of Distortion Area,")
				   _T("(4)Angle of Distortion Area,")
				   _T("(5)Angle of Distortion Area,")
				   _T("(6)Angle of Distortion Area,")
				   _T("(7)Angle of Distortion Area,")
				   _T("(8)Angle of Distortion Area,")
				   _T("(9)Angle of Distortion Area,")
				   _T("(10)Angle of Distortion Area,")
				   _T("(11)Angle of Distortion Area,")
				   _T("Max Error,")
				   _T("Rib assy angle,")
				   _T("Max angle range,")
				   _T("\n"));
		mFile.WriteString(str);
		LidarNo = 1;
	}
	else
	{	
		mFile.Open(Path,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate);
		if(isGetLidarNo == 1)
		{
			LidarNo++;
		}
		else
		{
			CString readstr;
			while(mFile.ReadString(readstr)) LidarNo++;
			isGetLidarNo = 1;
		}
	}
	
	mFile.SeekToEnd();
	str.Format(_T("%d,")_T("%s")_T("\n"),LidarNo,"NG");
	mFile.WriteString(str);
	
	mFile.Close();
}

 

你可能感兴趣的:(MFC)