using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Aspose.Cells; using Newtonsoft.Json; namespace StartServerWPF.Models { public class WorkareaModel { [JsonProperty("StationConfig")] public StationConfigModel StationConfig { get; set; } [JsonIgnore] public List Stations { get; set; } public List CreateStationFromCSV(string fn) { if (!File.Exists(fn)) return null; List stations = new List(); Aspose.Cells.TxtLoadOptions lo = new TxtLoadOptions(); //Debug.WriteLine(Encoding.Default.ToString()); lo.Encoding = Encoding.Default;//设置编码方式 Workbook workbook = new Workbook(fn, lo); //配置读取文件的类型(CSV) workbook.FileFormat = FileFormatType.Csv;//可在此配置Excel文件类型 Worksheet worksheet = workbook.Worksheets[0];//默认第一个Sheet页 Cells cells = worksheet.Cells; //读取到DataTable中 DataTable dt = cells.ExportDataTableAsString(0, 0, cells.MaxDataRow + 1, cells.MaxColumn + 1, true); for (int i = 0; i < dt.Rows.Count; i++) { DataRow row = dt.Rows[i]; StationControlModel model = new StationControlModel(); model.NetWork = row[0].ToString(); model.Num = row[1].ToString(); model.Coordinate=new Coordinate3D(double.Parse(row[2].ToString()), double.Parse(row[3].ToString()), double.Parse(row[4].ToString())); model.Sens = double.Parse(row[5].ToString()); model.BeginUseTime = DateTime.Parse(row[6].ToString()); model.StopUseTime = DateTime.Parse(row[7].ToString()); model.Location=this.StationConfig.Location; stations.Add(model); } //释放资源 workbook = null; worksheet = null; return stations; } } public class StationConfigModel { [JsonProperty("Network")] public string Network { get; set; } [JsonProperty("Location")] public string Location { get; set; } [JsonProperty("Channels")] public string[] Channels { get; set; } [JsonProperty("StationCoordCsvPath")] public string StationCoordCsvPath { get; set; } } public class Coordinate3D { [JsonProperty("X")] public double X { get; set; } [JsonProperty("Y")] public double Y { get; set; } [JsonProperty("Z")] public double Z { get; set; } public Coordinate3D() { } public Coordinate3D(double x,double y,double z) { X= x; Y= y; Z= z; } } public enum WellType { Wellhead=0, TargetLayer=1 } }