winform中,输入excel文件名,在文件中查找。如果找到,就打开它。
时间: 2023-12-10 11:42:28
浏览: 55
以下是一个简单的WinForm示例[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083),可以用于在文件中查找并打开[excel文件](https://geek.csdn.net/educolumn/058a2f001dec80db1ef2d7bf8bc67c6b?spm=1055.2569.3001.10083):
private void btnSearch_Click(object sender, EventArgs e)
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm";
openFileDialog1.Title = "Select an Excel File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
[string](https://geek.csdn.net/edu/8802d631b97a4a6af1f4d0bbf8527465?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083) filePath = openFileDialog1.FileName;
if (File.Exists(filePath))
Excel.Applic[ati](https://geek.csdn.net/educolumn/150d7073277950db5f09620704e791cf?spm=1055.2569.3001.10083)on excelApp = new Excel.Applic[ati](https://geek.csdn.net/educolumn/150d7073277950db5f09620704e791cf?spm=1055.2569.3001.10083)on();
Excel.Workbook workbook = null;
workbook = excelApp.Workbooks.Open(filePath);
workbook.Activate();
```