导入文件,谢谢啊
private void toolStripButton1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = Application.StartupPath;
open.Filter = "Excel 文件|*.xls";
open.FileName = "请选择Excel文件";
if (DialogResult.OK == open.ShowDialog())
{
this.toolexl.Text = open.FileName;
bindData();
}
}
这是一个按钮后面导入文件的代码,谁能帮我解释一下啊?
------解决方案--------------------
首先要了解OpenFileDialog 类 参考http://msdn.microsoft.com/zh-cn/library/system.windows.forms.openfiledialog(VS.80).aspx
更详细属性说明请参考http://www.cnblogs.com/GT_Andy/archive/2010/02/05/1921861.html
C# code
private void toolStripButton1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();//声明一个OpenFileDialog类的对象
open.InitialDirectory = Application.StartupPath;//InitialDirectory为对话框的初始目录
open.Filter = "Excel 文件|*.xls";//筛选条件,你应用这个控件的时候看看能观察到的文件类型只有Excel类型就明白什么含义了
open.FileName = "请选择Excel文件";//就是默认打开框位置的初始值,你看看这段文本在控件的什么位置就清楚了
if (DialogResult.OK == open.ShowDialog())//当用户点击控件中的“打开”时
{
this.toolexl.Text = open.FileName;//将打开的路径传给toolexl的Text属性
bindData();
}
}