【发布时间】:2015-06-07 02:18:43
【问题描述】:
string file = "";
int size = -1;
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
openFileDialog1.Filter = "Excel |*.xlsx"; //"Excel Files|(*.xlsx, *.xls)|*.xlsx;*.xls";
openFileDialog1.FilterIndex = 1;
if(result == DialogResult.OK) // Test result.
{
file = openFileDialog1.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
}
catch(System.IO.IOException)
{
}
}
tempLBL.Text = file;
我还测试了上面评论的过滤器。 当我浏览时它没有显示任何过滤器......并显示所有文件。我需要的是,当点击浏览按钮时,只向用户显示 XLSX 或 XLS 文件。
提前致谢
【问题讨论】:
标签: c# excel openfiledialog