如何从Windows窗体中的textBox获取Excel文件路由 [英] How get Excel file route from textBox in Windows Forms
问题描述
Hello Comunity。
Hello Comunity.
我希望在Visual Studio 2012中使用OleDb将Excel文件导入我的项目。我可以导入文件,提供完整的路径,如:
I want import an Excel file to my project in Visual Studio 2012 with OleDb. I can import the file giving complete route to the method like:
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\Users\Maria\Desktop\Test.xlsx");
但我想导入文件从textBox获取路径并单击按钮打开它。我怎么做?
But I want import the file getting the pathfrom a textBox and open it clicking a button. How I can do this?
谢谢
PD:抱歉英语不好。
PD: Sorry for bad english.
推荐答案
如果您已经创建了一个Windows窗体应用程序,那么您只需要在窗体上添加一个文本框,然后您可以在代码中执行以下操作来读取在TextBox中输入的值。
If you have created already a Windows Form application, then you just need to add a textbox on the form and then you can do the following in code to read the value entered in the TextBox.
例如,您将其名称设置为 txtBoxPath ,在这种情况下您只需要执行此操作:
For example, you are setting the name of it to txtBoxPath,in that case you just need to do this:
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(txtBoxPath.Text);
希望它有帮助。
Hope it Helps.
这篇关于如何从Windows窗体中的textBox获取Excel文件路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!