//从XML文件读取并检测文件中的成员是否存在 /// <summary> /// 从项目文件中读取数据,并打开相应的Excel程序与工作簿 /// </summary> /// <remarks></remarks> public void LoadFromXmlFile() { //载入文档 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(this.P_FilePath); // clsData_FileContents FC = new clsData_FileContents(); XMLNode eleRoot = xmlDoc.SelectSingleNode(System.Convert.ToString(My.Settings.Default.ProjectName)); //这里可以尝试用GetElementById XmlElement Node_DataBase = eleRoot.SelectSingleNode(DataBasePath.Nd1_DataBasePaths); if (Node_DataBase == null) { return; } // ---------------------- 读取文档 ------------------------ // ---------------------- 读取文档 ------------------------ XmlNodeList eleWkbks = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_WorkbooksInProject); foreach (XmlElement eleWkbk in eleWkbks) { string strWkbkPath = eleWkbk.InnerText; Workbook wkbk = ExcelFunction.MatchOpenedWkbk(wkbkPath: ref strWkbkPath, Application: ref this.F_Application, OpenIfNotOpened: true); if (wkbk != null) { FC.lstWkbks.Add(wkbk); } else //此工作簿不存在,或者是没有成功赋值 { this.F_blnFileValid = false; this.F_lstErrorMessage.Add("The Specified Workbook is not found : " + strWkbkPath); } } // ---------------- 施工进度工作表 bool blnNodeForWorksheetValidated = false; XmlNodeList eleSheetsProgress = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_Progress); foreach (XmlElement eleSheetProgress in eleSheetsProgress) { Worksheet shtProgress = ValidateNodeForWorksheet(eleSheetProgress, FC, ref blnNodeForWorksheetValidated); if (blnNodeForWorksheetValidated) { FC.lstSheets_Progress.Add(shtProgress); } } // ---------------- 开挖平面图工作表 XmlNodeList eleSheetPlanView = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_PlanView); var shtPlanView = ValidateNodeForWorksheet((System.Xml.XmlElement)(eleSheetPlanView.Item(0)), FC, ref blnNodeForWorksheetValidated); FC.Sheet_PlanView = shtPlanView; // ---------------- 开挖剖面图工作表 XmlNodeList eleSheetSectionalView = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_SectionalView); Worksheet shtSectionalView = ValidateNodeForWorksheet((System.Xml.XmlElement)(eleSheetSectionalView.Item(0)), FC, ref blnNodeForWorksheetValidated); FC.Sheet_Elevation = shtSectionalView; // ---------------- 测点坐标工作表 XmlNodeList eleSheetPointCoordinates = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_PointCoordinates); Worksheet shtPoint = ValidateNodeForWorksheet((System.Xml.XmlElement)(eleSheetPointCoordinates.Item(0)), FC, ref blnNodeForWorksheetValidated); FC.Sheet_PointCoordinates = shtPoint; // ---------------- 开挖工况工作表 XmlNodeList eleWorkingStage = Node_DataBase.GetElementsByTagName(DataBasePath.Nd2_WorkingStage); Worksheet shtWorkingStage = ValidateNodeForWorksheet((System.Xml.XmlElement)(eleWorkingStage.Item(0)), FC, ref blnNodeForWorksheetValidated); FC.Sheet_WorkingStage = shtWorkingStage; // this.P_FileContents = FC; //刷新主程序界面显示 APPLICATION_MAINFORM.MainForm.MainUI_ProjectOpened(); }