导入导出功能,在调用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(); } }

 

相关文章:

  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-06-18
  • 2022-01-15
  • 2022-12-23
  • 2021-10-29
猜你喜欢
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案