导入导出功能,在调用ShowDialog时的错误,解决办法如下:
WinForm窗体的入口点:
/// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] private static void Main(String[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new LoginForm()); }
报错页面程序如下:
public string importPath=""; //全局变量,用于显示导入文件路劲 private void btnImport_Click(object sender, EventArgs e) { Thread importThread = new Thread(new ThreadStart(ImportDialog)); importThread.SetApartmentState(ApartmentState.STA); //重点 importThread.Start(); txtImportPath.Text = importPath; } public void ImportDialog() { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Excel文件|*.xls;*.xlsx"; if (open.ShowDialog() == DialogResult.OK) { importPath = open.FileName; ReadExcelToTable(importPath); UpdateArea(); } }
时间: 2024-10-14 10:47:14