大家好,在此先感谢您,我有一个下面给定格式的 .csv 文件。我需要在 c# windows 应用程序的 datagridview 中显示这个值,如数字日期时间消息的三列,其余的一切都将被忽略..包括双引号、短信、交付请帮助我,我是新手,请帮助..
sms,deliver,"+919999999999","","","2013.08.01 12:52","","AVAILABLE ON RENT 3BHK Flat 102 1Floor @Mansarovar,mount lovely rd., Malabar Hill. West Seafacing .partial海景建筑在斜坡 通风良好 宽敞1800地毯 3bhk,商店+仆人房间+浴室,独立入口+百叶窗关闭车库260capet,家具齐全,白色家电立即出租。"
sms,deliver,"+919999999999","","","2013.08.01 09:40","","Khar 的以下公寓出租:SHIKHA, Near SHATRANJ, Off Carter Road, Khar Garden 面向 1500 sq.英尺 3BHK 半家具 + 1 个停车位。租赁 @ Rs. 1.25 lacs 立即拥有。2 小时通知检查。--Rohit J."
sms,deliver,"+919999999999","","","2013.07.31 20:37","","direct 1bhk( Deepak silverene@55 Hill n sea@70 Vindhyachal@70 2bhk West side@80 Harmony @ 90 Neptune@1.6 Bldg no 22@55 3bhk Elco Residency@1.5 Firdos manzil@1.10 Radhe narayan@1.25 Vertical bliss@2.75 4bhk Vinayk heights@4lac RawthanI garden@1.75 Cl/sms"
我试过这个代码..
private void button1_Click(object sender, EventArgs e)
{
if (System.IO.File.Exists("E:\\messages.csv"))
{
System.IO.StreamReader fileReader = new StreamReader("E:\\messages.csv");
//Checking the end of file's content
if (fileReader.Peek() != -1)
{
string fileRow = fileReader.ReadLine();
string[] fileDataField = fileRow.Split(',');
int count = fileDataField.Count();
//Adding Column Header to DataGridView
for (int i = 0; i < count; i++)
{
DataGridViewTextBoxColumn columnDataGridTextBox = new DataGridViewTextBoxColumn();
columnDataGridTextBox.Name = fileDataField[i];
columnDataGridTextBox.HeaderText = fileDataField[i];
columnDataGridTextBox.Width = 120;
dataGridView1.Columns.Add(columnDataGridTextBox);
}
//Adding Data to DataGridView
while (fileReader.Peek() != -1)
{
fileRow = fileReader.ReadLine();
fileDataField = fileRow.Split(',');
dataGridView1.Rows.Add(fileDataField);
}
}
//Close the StreamReader
fileReader.Close();
}
}