回复 1楼taxsoft的帖子
Spread 现在并没有抛出文件被占用的异常,可以通过 File.OpenWrite 来尝试打开文件,然后无法打开会抛出详细异常信息:
- private void btnOpen_Click(object sender, EventArgs e)
- {
- OpenFileDialog dlgOpen = new OpenFileDialog();
- if (dlgOpen.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- try
- {
- FileStream fs = File.OpenWrite(dlgOpen.FileName);
- fs.Close();
- var excel = fpSpread1.IsExcelFile(dlgOpen.FileName);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
复制代码 |