把一个EXCEL文件转化成一个TXT文本文件,然后在导入这个文本文件,用DATAGRIDVIEW输出数据。
我是直接从EXCEL文件导入的,但是这期间遇到一个问题,就是导入的时候,DATAGRIDVIEW输出的数据,有些为空。
但是只要把最前面的几条数据:前加字母,就好了。例如:1234 改成:A1234,
这样就不会出现问题。我导入EXCEL文件的代码如下:
OpenFileDialog openFileDialog1 = new OpenFileDialog();
bool isexcel = true;
if (isexcel)
openFileDialog1.Filter = "Excel files (*.xls)|*.xls";
else
openFileDialog1.Filter = "文本(*.txt)|*.txt";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName != string.Empty)
{
try
{
_lastrowindex = -1;
_errorTable = new OrderServiceAgent.DataSource.OrderDB.ErrorTableDataTable();
progressBar1.Visible = true;
_messagelabel.Visible = true;
MakeContralAble(false);
backgroundWorker1.RunWorkerAsync(openFileDialog1.FileName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
//System.Diagnostics.Process.Start(openFileDialog1.FileName);
MessageBox.Show(string.Format("导入文件出错:{0}", ex.Message));
}
}
bool isexcel = true;
if (isexcel)
openFileDialog1.Filter = "Excel files (*.xls)|*.xls";
else
openFileDialog1.Filter = "文本(*.txt)|*.txt";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName != string.Empty)
{
try
{
_lastrowindex = -1;
_errorTable = new OrderServiceAgent.DataSource.OrderDB.ErrorTableDataTable();
progressBar1.Visible = true;
_messagelabel.Visible = true;
MakeContralAble(false);
backgroundWorker1.RunWorkerAsync(openFileDialog1.FileName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
//System.Diagnostics.Process.Start(openFileDialog1.FileName);
MessageBox.Show(string.Format("导入文件出错:{0}", ex.Message));
}
}
是不是我这些代码有点错误,然后导入时出现了那些错误。