C#打开并读取已有文件中的数值
private static string[] info = new string[5]; // 设定信息
private void OpenExistedFile()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Excel文件(*.csv;)|*.csv"; //此处可以定义任意文件
ofd.ValidateNames = true;
ofd.CheckPathExists = true;
ofd.CheckFileExists = true;
ofd.InitialDirectory = GlobalData.saveToPath;
string[] temp = new string[2];
try
{
if (ofd.ShowDialog() == DialogResult.OK)
{
string strFileName = ofd.FileName;
info = ReadCSV(strFileName, info);
}
for(int i = 0; i < 24; i++)
{
temp = info[i].Split(',');
info[i] = temp[1]; // 读取的数据放入info数组中
}
}
catch
{
return;
}
}