//excel转换成xml事件 private void btnExcelToXML_Click(object sender, EventArgs e) { String excelDataPath = this.excelPath.Text; //excel文件的路径 String printPath = this.printPath.Text; //生成文件的路径 if (!Directory.Exists(printPath)) //生产xml的路径不存在 直接结束 { printPath = excelDataPath.Substring(0, excelDataPath.LastIndexOf("\\")); } XMLOperate xmlOperate = new XMLOperate(); ExcelOperate excelOperate = new ExcelOperate(); List <XMLObject> xmlObjectList = excelOperate.ExcelToXMLObject(excelDataPath); foreach (XMLObject xmlObject in xmlObjectList) { xmlOperate.ObjectToXMLFile(printPath, xmlObject); } MessageBox.Show("excel已经转成xml文件", "确定"); }