내 응용 프로그램에서
사용자가이 괜찮 작품에서하고있는 DataGridView에 내 보낸 CSV 파일 수 있지만이 일부 사소한 문제.
csv 파일에서 알다시피 쉼표 기호를 사용하여 항목을 분리하십시오.
때때로 셀 중 하나에 쉼표 (예 : 2,5 시간)가 있습니다.
csv를 가져올 때 쉼표 2, 5가 분리 기호로 생각됩니다.이 때문에 셀에 2를 넣고 다음 셀에 5를 넣습니다.
이 문제는 어떻게 해결할 수 있습니까?
이 가져 오기에 대한 내 CSV이다 CSV의
dataGridView1.Rows.Clear();
try
{
if (openFileCsv.ShowDialog() == DialogResult.OK)
{
string csvPath = openFileCsv.FileName;
if (System.IO.File.Exists(csvPath))
{
System.IO.StreamReader fileReader = new System.IO.StreamReader(csvPath, false);
//Reading Data
while (fileReader.Peek() != -1)
{
fileRow = fileReader.ReadLine();
fileDataField = fileRow.Split(',');
dataGridView1.Rows.Add(fileDataField);
}
fileReader.Dispose();
fileReader.Close();
}
else
{
MessageBox.Show("CSV Bestand niet gevonden.");
}
}
DataLoaded = true;
}
이것은 CSV 수출에 대한 내 코드입니다.
if (saveFileCsv.ShowDialog() == DialogResult.OK)
{
string CsvFpath = saveFileCsv.FileName;
try
{
System.IO.StreamWriter csvFileWriter = new System.IO.StreamWriter(CsvFpath, false);
int countColumn = dataGridView1.ColumnCount - 1;
int iColCount = dataGridView1.Columns.Count;
foreach (DataGridViewRow dataRowObject in dataGridView1.Rows)
{
//Checking for New Row in DataGridView
if (!dataRowObject.IsNewRow)
{
string dataFromGrid = "";
dataFromGrid = dataRowObject.Cells[0].Value.ToString();
for (int i = 1; i <= countColumn; i++)
{
dataFromGrid = dataFromGrid + ',' + dataRowObject.Cells[i].Value.ToString();
}
//Writing Data Rows in File
csvFileWriter.WriteLine(dataFromGrid);
}
}
csvFileWriter.Flush();
csvFileWriter.Close();
}
catch (Exception exceptionObject)
{
MessageBox.Show(exceptionObject.ToString());
}
판독 CSV 파일 대신하여 filerow 분할 판독 데이터 테이블로 직접 ','. –
어떻게하면 좋을까요? – PandaNL