/// <summary> ///获取xls文件 WeightSortData /// </summary> /// <param name="strFilePath"></param> /// <returns></returns> public static WeightSortData GetXlsImportSortData(string strFilePath) { WeightSortData sortData = null; try { if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return(sortData); } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; if (count > 0) { sortData = new WeightSortData(); sortData.sortName = table.Rows[0][0].ToString(); List <WeightData> lstWeightData = new List <WeightData>(); for (int i = 0; i < count; i++) { WeightData data = new WeightData(); data.nID = Convert.ToInt32(table.Rows[i][1].ToString()); data.weightName = table.Rows[i][2].ToString(); data.weightValue = Convert.ToDouble(table.Rows[i][4].ToString()); data.strRemark = table.Rows[i][5].ToString(); data.nParentID = Convert.ToInt32(table.Rows[i][6].ToString()); lstWeightData.Add(data); } sortData.lstWeightData = lstWeightData; } } } catch { MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误"); XCommon.XLog.Write("导入文件\"" + strFilePath + "\"格式错误"); return(null); } return(sortData); }
/// <summary> /// 判断导入重量数据文件格式是否正确 /// </summary> /// <param name="strType"></param> /// <param name="path"></param> /// <param name="strPath"></param> /// <returns></returns> private bool IsImortWeightDataFileFormat(string strPath) { bool IsRight = false; try { //重量数据 if (strPath.EndsWith(".xml")) { XmlNode node = null; XmlDocument doc = new XmlDocument(); doc.Load(strPath); node = doc.SelectSingleNode("重量分类/重量分类名称"); if (node != null) { IsRight = true; } } else if (strPath.EndsWith(".xls")) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strPath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return(false); } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); if (table.Columns[0].Caption == "重量分类名称") { IsRight = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } return(IsRight); }
/// <summary> /// 获取excle文件数据 /// </summary> /// <param name="strFilePath"></param> /// <returns></returns> private List <ParaData> GetFileParaData(string strFilePath) { List <ParaData> lstParaData = new List <ParaData>(); if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return(lstParaData); } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; for (int i = 0; i < count; i++) { ParaData para = new ParaData(); para.paraName = table.Rows[i][0].ToString(); para.paraUnit = table.Rows[i][1].ToString(); para.paraType = Convert.ToInt32(table.Rows[i][2].ToString()); para.paraValue = Convert.ToDouble(table.Rows[i][3].ToString()); para.strRemark = table.Rows[i][4].ToString(); lstParaData.Add(para); } } return(lstParaData); }
private List<CorePointData> GetExcelListCorePointData(string strFilePath) { List<CorePointData> lstCorePtData = null; try { if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return lstCorePtData; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; //列标题重复 table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; if (count > 0) { lstCorePtData = new List<CorePointData>(); for (int i = 0; i < table.Rows.Count; i++) { CorePointData pt = new CorePointData(); pt.pointName = table.Rows[i][0].ToString(); pt.pointXValue = Convert.ToDouble(table.Rows[i][3].ToString()); pt.pointYValue = Convert.ToDouble(table.Rows[i][4].ToString()); lstCorePtData.Add(pt); } } } } catch { XLog.Write("导入文件\"" + strFilePath + "\"格式错误"); MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误"); return null; } return lstCorePtData; }
private CoreEnvelopeDesign GetExcelCoreDesignData(string strFilePath) { CoreEnvelopeDesign CoreData = null; try { if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return CoreData; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; //列标题重复 table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; string strCoreEnvelope = string.Empty; if (count > 0) { CoreData = new CoreEnvelopeDesign(); CoreData.Id = bllCoreEnvelopeDesign.GetMaxId() + 1; CoreData.DesignData_Name = table.Rows[0][0].ToString(); CoreData.DesignData_Submitter = table.Rows[0][1].ToString(); CoreData.Helicopter_Name = table.Rows[0][2].ToString(); CoreData.DataRemark = table.Rows[0][3].ToString(); CoreData.LastModify_Time = table.Rows[0][4].ToString(); CoreData.DesignTaking_Weight = Convert.ToDouble(table.Rows[0][5]); if (table.Rows[0][6].ToString() != string.Empty) { for (int i = 0; i < table.Rows.Count; i++) { strCoreEnvelope += table.Rows[i][6].ToString() + ":" + "横坐标(毫米)、纵坐标(千米)、" + table.Rows[i][7].ToString() + "、" + table.Rows[i][8].ToString() + "|"; } strCoreEnvelope = strCoreEnvelope.Substring(0, strCoreEnvelope.Length - 1); } CoreData.CoreEnvelope = strCoreEnvelope; } } } catch { XLog.Write("导入文件\"" + strFilePath + "\"格式错误"); MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误"); return null; } return CoreData; }
/// <summary> /// 判断导入重心数据文件格式是否正确 /// </summary> /// <param name="strType"></param> /// <param name="path"></param> /// <param name="strPath"></param> /// <returns></returns> private bool IsImorCoreDataFileFormat(string strType, string strPath) { bool IsRight = false; try { //重心数据 if (strType == "core") { if (strPath.EndsWith(".xml")) { XmlNode node = null; XmlDocument doc = new XmlDocument(); doc.Load(strPath); node = doc.SelectSingleNode("重心数据/重心坐标列表"); if (node != null) { IsRight = true; } } if (strPath.EndsWith(".xls")) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strPath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return false; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); if (table.Columns[0].Caption == "重心坐标点名称") { IsRight = true; } } } ///重量设计 if (strType == "coreEnvelope") { if (strPath.EndsWith(".xml")) { XmlNode node = null; XmlDocument doc = new XmlDocument(); doc.Load(strPath); node = doc.SelectSingleNode("重心包线设计数据/设计数据名称"); if (node != null) { IsRight = true; } } if (strPath.EndsWith(".xls")) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strPath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return false; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); if (table.Columns[0].Caption == "设计数据名称") { IsRight = true; } } } } catch { return false; } return IsRight; }
/// <summary> ///xls文件转换成WeightSortData类型 /// </summary> /// <param name="strFilePath">文件路径</param> /// <returns>返回WeightSortData类型</returns> public static WeightSortData GetXlsImportSortData(string strFilePath) { WeightSortData sortData = null; try { if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return sortData; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; if (count > 0) { sortData = new WeightSortData(); sortData.sortName = table.Rows[0][0].ToString(); List<WeightData> lstWeightData = new List<WeightData>(); for (int i = 0; i < count; i++) { WeightData data = new WeightData(); data.nID = Convert.ToInt32(table.Rows[i][1].ToString()); data.weightName = table.Rows[i][2].ToString(); data.weightValue = Convert.ToDouble(table.Rows[i][4].ToString()); data.strRemark = table.Rows[i][5].ToString(); data.nParentID = Convert.ToInt32(table.Rows[i][6].ToString()); lstWeightData.Add(data); } sortData.lstWeightData = lstWeightData; } } } catch { XLog.Write("导入文件\"" + strFilePath + "\"格式错误"); MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误"); return null; } return sortData; }
/// <summary> /// 判断导入评估数据文件格式是否正确 /// </summary> /// <param name="strType"></param> /// <param name="path"></param> /// <param name="strPath"></param> /// <returns></returns> private bool IsImorCoreEvaluationDataFormat(string strPath) { bool IsRight = false; //重心数据 if (strPath.EndsWith(".xml")) { XmlNode node = null; XmlDocument doc = new XmlDocument(); doc.Load(strPath); node = doc.SelectSingleNode("重心离散点评估数据/离散点评估数据列表"); if (node != null) { IsRight = true; } } if (strPath.EndsWith(".xls") || strPath.EndsWith(".xlsx")) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strPath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return false; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); if (table.Columns != null && table.Columns.Count > 0) { if (table.Columns[0].Caption == "离散点重心坐标名称") { IsRight = true; } } } return IsRight; }
/// <summary> /// 获取离散评估数据 /// </summary> /// <param name="strFilePath"></param> /// <returns></returns> private List<int> GetExcelCoreEvaluationData(string strFilePath) { lstCoreEvaluationData = null; //评估数据 List<int> lstCoreEvaluation = null; if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return lstCoreEvaluation; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; //列标题重复 table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; if (count > 0) { lstCoreEvaluationData = new List<CorePointData>(); lstCoreEvaluation = new List<int>(); int t = -1; for (int i = 0; i < table.Rows.Count; i++) { CorePointData pt = new CorePointData(); pt.pointName = table.Rows[i][0].ToString(); pt.pointXValue = Convert.ToDouble(table.Rows[i][3].ToString()); pt.pointYValue = Convert.ToDouble(table.Rows[i][4].ToString()); t = Convert.ToInt32(table.Rows[i][5].ToString()); lstCoreEvaluation.Add(t); lstCoreEvaluationData.Add(pt); } } } return lstCoreEvaluation; }
/// <summary> /// 获取excle文件数据 /// </summary> /// <param name="strFilePath"></param> /// <returns></returns> private List<ParaData> GetFileParaData(string strFilePath) { List<ParaData> lstParaData = new List<ParaData>(); if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return lstParaData; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; for (int i = 0; i < count; i++) { ParaData para = new ParaData(); para.paraName = table.Rows[i][0].ToString(); para.paraEnName = table.Rows[i][1].ToString(); para.paraUnit = table.Rows[i][2].ToString(); para.paraType = Convert.ToInt32(table.Rows[i][3].ToString()); para.paraValue = Convert.ToDouble(table.Rows[i][4].ToString()); para.strRemark = table.Rows[i][5].ToString(); lstParaData.Add(para); } } return lstParaData; }
/// <summary> /// 获取Excel文件的重量设计对象 /// </summary> /// <param name="strFilePath"></param> /// <returns></returns> private WeightDesignData GetExcelWeightDesignData(string strFilePath) { WeightDesignData weightData = null; try { if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return weightData; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; if (count > 0) { string strSortName = string.Empty; weightData = new WeightDesignData(); weightData.Id = bllDesignData.GetMaxId() + 1; weightData.DesignData_Name = table.Rows[0][0].ToString(); weightData.DesignData_Submitter = table.Rows[0][1].ToString(); weightData.Helicopter_Name = table.Rows[0][2].ToString(); weightData.DataRemark = table.Rows[0][3].ToString(); weightData.LastModify_Time = table.Rows[0][4].ToString(); weightData.DesignTaking_Weight = Convert.ToDouble(table.Rows[0][5]); if (table.Rows[0][6] is DBNull || table.Rows[0][6].ToString() == string.Empty) { weightData.MainSystem_Name = string.Empty; } else { strSortName = table.Rows[0][6].ToString(); string strMainSystemWeight = strSortName + "|"; string strFH = "、"; for (int i = 0; i < count; i++) { strMainSystemWeight += table.Rows[i][8].ToString() + strFH + table.Rows[i][7].ToString() + strFH + table.Rows[i][9].ToString() + strFH + table.Rows[i][10].ToString() + strFH + table.Rows[i][12].ToString() + "|"; } weightData.MainSystem_Name = strMainSystemWeight; } } } } catch { XLog.Write("导入文件\"" + strFilePath + "\"格式错误"); MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误"); return null; } return weightData; }
private List<ParaData> GetExcelRatioData(string strFilePath) { List<ParaData> lstParaData = null; try { if (File.Exists(strFilePath)) { ExcelLib OpExcel = new ExcelLib(); //指定操作的文件 OpExcel.OpenFileName = strFilePath; //打开文件 if (OpExcel.OpenExcelFile() == false) { return lstParaData; } //取得所有的工作表名称 string[] strSheetsName = OpExcel.getWorkSheetsName(); //默认操作第一张表 OpExcel.SetActiveWorkSheet(1); System.Data.DataTable table; table = OpExcel.getAllCellsValue(); OpExcel.CloseExcelApplication(); int count = table.Rows.Count; if (count > 0) { lstParaData = new List<ParaData>(); for (int i = 0; i < count; i++) { ParaData data = new ParaData(); data.paraName = table.Rows[i][0].ToString(); data.paraEnName = table.Rows[i][1].ToString(); data.paraUnit = table.Rows[i][2].ToString(); data.paraType = Convert.ToInt32(table.Rows[i][3].ToString()); data.paraValue = Convert.ToDouble(table.Rows[i][4].ToString()); data.strRemark = table.Rows[i][5].ToString(); lstParaData.Add(data); } } } } catch { XLog.Write("导入文件\"" + strFilePath + "\"格式错误"); MessageBox.Show("导入文件\"" + strFilePath + "\"格式错误"); return null; } return lstParaData; }