From 4d95d752823b1f5362c5d639001444b260b90395 Mon Sep 17 00:00:00 2001 From: Shuxia Ning <NingShuxia0927@outlook.com> Date: 星期五, 10 一月 2025 16:12:57 +0800 Subject: [PATCH] 阀门曲线 导入 编辑控件 --- WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 179 insertions(+), 0 deletions(-) diff --git a/WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs b/WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs index 3b84998..88e5759 100644 --- a/WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs +++ b/WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs @@ -46,6 +46,30 @@ } + public static void ExportValveTemplate(string file_path) + { + NPOI.HSSF.UserModel.HSSFWorkbook theBook = new NPOI.HSSF.UserModel.HSSFWorkbook(); + + var theSheet1 = theBook.CreateSheet("娴侀噺鎹熷け"); + NPOI.SS.UserModel.IRow rowTile1 = theSheet1.CreateRow(0); + rowTile1.CreateCell(0).SetCellValue("寮�搴� %"); + rowTile1.CreateCell(1).SetCellValue("娴侀噺 m鲁/h"); + rowTile1.CreateCell(2).SetCellValue("姘村ご鎹熷け m"); + + var theSheet2 = theBook.CreateSheet("寮�搴︽崯澶�"); + NPOI.SS.UserModel.IRow rowTile2 = theSheet2.CreateRow(0); + rowTile2.CreateCell(0).SetCellValue("寮�搴� %"); + rowTile2.CreateCell(1).SetCellValue("鎹熷け绯绘暟 k"); + + + theSheet1.ForceFormulaRecalculation = true; + theSheet2.ForceFormulaRecalculation = true; + + using FileStream fs = File.OpenWrite(file_path); + theBook.Write(fs); + } + + #endregion #region Parse @@ -263,6 +287,161 @@ return ""; } + public static string ParseValveExcel(string fileName, out List<(Yw.Ahart.eCurveType CurveType, List<Yw.Geometry.Point2d> DefPointList, int Opening)> list) + { + list = new List<(Ahart.eCurveType CurveType, List<Geometry.Point2d> DefPointList, int Opening)>(); + if (!File.Exists(fileName)) + return "鏂囦欢涓嶅瓨鍦�"; + int line = 0; + + //鍒濆鍖栨枃浠� + NPOI.HSSF.UserModel.HSSFWorkbook theBook = null; + using (FileStream file = new(fileName, FileMode.Open, FileAccess.Read)) + theBook = new NPOI.HSSF.UserModel.HSSFWorkbook(file); + + + //妫�鏌ヨ〃鏍兼槸鍚︾鍚� + NPOI.SS.UserModel.ISheet sheet_ql = theBook.GetSheet("娴侀噺鎹熷け"); + if (sheet_ql != null) + { + //鏍囬琛� + int title_line_index = 0; + //寮�搴﹀垪 + int col_index_opening = 0; + //娴侀噺鍒� + int col_index_flow = 1; + //姘村ご鎹熷け鍒� + int col_index_head_loss = 2; + + var row_title = sheet_ql.GetRow(title_line_index); + if (row_title == null) + { + return ("绗竴琛岀涓�鍒椾笉鑳界┖"); + } + + //寮�濮嬭鍙栫殑琛� + int start_line = title_line_index + 1; + var cell_0 = row_title.GetCell(0); + if (cell_0 == null) + { + return ("鏃犳硶璇诲彇琛ㄥご鏂囦欢"); + } + + + + NPOI.SS.UserModel.IRow row_temp = null; + NPOI.SS.UserModel.ICell cell; + + var cell_value_list = new List<(double Opening, double Flow, double HeadLoss)>(); + for (line = start_line; line < 1000; line++) + { + row_temp = sheet_ql.GetRow(line); + if (row_temp == null) + break; + + cell = row_temp.GetCell(col_index_opening); + if (cell == null) + break; + if (!ParseCellValue(cell, out double opening)) + break; + if (opening < 0 || opening > 100) + break; + + cell = row_temp.GetCell(col_index_flow); + if (cell == null) + break; + if (!ParseCellValue(cell, out double flow)) + break; + if (flow < 0) + break; + + cell = row_temp.GetCell(col_index_head_loss); + if (cell == null) + break; + if (!ParseCellValue(cell, out double head_loss)) + break; + if (head_loss < 0) + break; + + cell_value_list.Add((opening, flow, head_loss)); + } + + var opening_group = cell_value_list.GroupBy(x => x.Opening); + foreach (var item in opening_group) + { + var pt_list = item.Select(x => new Yw.Geometry.Point2d(x.Flow, x.HeadLoss)); + list.Add((Yw.Ahart.eCurveType.QL, pt_list.ToList(), (int)item.Key)); + } + } + + + //妫�鏌ヨ〃鏍兼槸鍚︾鍚� + NPOI.SS.UserModel.ISheet sheet_ol = theBook.GetSheet("寮�搴︽崯澶�"); + if (sheet_ol != null) + { + //鏍囬琛� + int title_line_index = 0; + //寮�搴﹀垪 + int col_index_opening = 0; + //鎹熷け绯绘暟鍒� + int col_index_k = 1; + + var row_title = sheet_ol.GetRow(title_line_index); + if (row_title == null) + { + return ("绗竴琛岀涓�鍒椾笉鑳界┖"); + } + + //寮�濮嬭鍙栫殑琛� + int start_line = title_line_index + 1; + var cell_0 = row_title.GetCell(0); + if (cell_0 == null) + { + return ("鏃犳硶璇诲彇琛ㄥご鏂囦欢"); + } + + + + NPOI.SS.UserModel.IRow row_temp = null; + NPOI.SS.UserModel.ICell cell; + + var pt_list = new List<Yw.Geometry.Point2d>(); + for (line = start_line; line < 1000; line++) + { + row_temp = sheet_ol.GetRow(line); + if (row_temp == null) + break; + + cell = row_temp.GetCell(col_index_opening); + if (cell == null) + break; + if (!ParseCellValue(cell, out double opening)) + break; + if (opening < 0 || opening > 100) + break; + + cell = row_temp.GetCell(col_index_k); + if (cell == null) + break; + if (!ParseCellValue(cell, out double k)) + break; + if (k < 0) + break; + + pt_list.Add(new Geometry.Point2d(opening, k)); + } + + list.Add((Yw.Ahart.eCurveType.OL, pt_list.ToList(), 100)); + } + + if (list == null || !list.Any()) + { + return ("琛ㄦ牸涓嶇鍚堟牸寮�"); + } + + return ""; + } + private static bool ParseCellValue(NPOI.SS.UserModel.ICell cell, out double cell_value) { cell_value = 0; -- Gitblit v1.9.3