c#打开excel出现的问题,哪位大侠帮解决下?(下面是代码)
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();
}
错误信息:
------解决方案--------------------excel1.Application.Workbooks.Open(filename)试试看。我记得后面参数不写也行。
------解决方案--------------------missing默认个数查下!
------解决方案--------------------string filename = file.Substring(index1 + 1);
Microsoft.Office.Interop.Excel.Workbook book1 = excel1.Application.Workbooks.Open(filename............
这个filename是不是没有路径只有文件名?参数换成file看看。