OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Shape地图文件(*.xlsx)|*.xlsx|全部文件(*.*)|*.*";
            dlg.Title = "打开Shape地图文件";
            dlg.Multiselect = true;
            dlg.ShowDialog();
            string[] files = dlg.FileNames;
            foreach (string file in files)
            {
                int index1 = file.LastIndexOf("\\");
                //string filepath = file.Substring(0, index1);
                string filename = file.Substring(index1 + 1);
                
                Microsoft.Office.Interop.Excel.Application excel1 = new Microsoft.Office.Interop.Excel.Application();
                listBox1.Items.Add(filepath);
                listBox1.Items.Add(filename);                object missing= System.Reflection.Missing.Value;                Microsoft.Office.Interop.Excel.Workbook book1 = excel1.Application.Workbooks.Open(filename, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);(这条语句报的错)
                book1.SaveAs("D:\\text.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                excel1.Quit();
             }
错误信息:

解决方案 »

  1.   

    excel1.Application.Workbooks.Open(filename)试试看。我记得后面参数不写也行。
      

  2.   

    string filename = file.Substring(index1 + 1);
    Microsoft.Office.Interop.Excel.Workbook book1 = excel1.Application.Workbooks.Open(filename............
    这个filename是不是没有路径只有文件名?参数换成file看看。
      

  3.   

    filename是只有名字,open的参数里也只要求是名字,不是完整的路径
      

  4.   

    我们的程序集不同?以前的项目里的找不到了,我现写了一个,打开没问题啊?Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
    app.Visible = true;
    Microsoft.Office.Interop.Excel.Workbook book1 = app.Workbooks.Open("e:\\oldpc\\Book1.xlsx");
      

  5.   


    楼上正解,filename是excel文件的路径。