本文用到Excel.dll 的链接库文后放资源链接。string[,] addressItem;string[,] nameCus;string[,] type;public void OpenExcel(string strFileName){object missing System.Reflection.Missing.Value;Microsoft.Office.Interop.Excel.Application excel new Microsoft.Office.Interop.Excel.Application();//lauch excel applicationif (excel null){}else{excel.Visible false; excel.UserControl true;// 以只读的形式打开EXCEL文件Workbook wb excel.Application.Workbooks.Open(strFileName, missing, true, missing, missing, missing,missing, missing, missing, true, missing, missing, missing, missing, missing);//取得第一个工作薄Worksheet ws (Worksheet)wb.Worksheets.get_Item(2);//取得总记录行数 (包括标题列)int rowsint ws.UsedRange.Cells.Rows.Count; //得到行数//int columnsint mySheet.UsedRange.Cells.Columns.Count;//得到列数//取得数据范围区域 (不包括标题列)Range address ws.Cells.get_Range(D2, D rowsint);Range name ws.Cells.get_Range(J2, J rowsint);Range stype ws.Cells.get_Range(C2, C rowsint);object[,] addressItem1 (object[,])address.Value2;object[,] nameCus1 (object[,])name.Value2;object[,] type1 (object[,])stype.Value2;addressItem new string[rowsint-1, 1];nameCus new string[rowsint-1, 1];type new string[rowsint-1, 1];for (int i 1; i rowsint-1; i){try{if (!string.IsNullOrEmpty(addressItem1[i, 1].ToString())){addressItem[i - 1, 0] addressItem1[i, 1].ToString();nameCus[i - 1, 0] nameCus1[i, 1].ToString();type[i - 1, 0] type1[i, 1].ToString();}}catch (Exception ex){throw ex;}}}excel.Quit(); excel null;Process[] procs Process.GetProcessesByName(excel);foreach (Process pro in procs){pro.Kill();//没有更好的方法,只有杀掉进程}GC.Collect();}public void SaveToXml(string path){XDocument xdoc1 new XDocument();XElement Pers new XElement(ReceiveChannels);for (int i 0; i addressItem.Length; i){XElement p1 new XElement(ConfigItem);p1.SetAttributeValue(Name, nameCus[i, 0]);p1.SetAttributeValue(Address, addressItem[i, 0]);p1.SetAttributeValue(DataType, type[i, 0]);p1.SetAttributeValue(IsArray, true);p1.SetAttributeValue(Size, 1);p1.SetAttributeValue(Lenth, 1);Pers.Add(p1);}xdoc1.Add(Pers);xdoc1.Save(path);}https://download.csdn.net/download/u013636149/11646985