/// <summary> /// 导出数据为原始数据 /// </summary> /// <param name="filePath">导出的文件路径</param> /// <param name="IsChinese">是否导出为中文</param> /// <returns></returns> public bool ExportToExcle(string filePath, ExportLanguageEnum exportLanguage) { FileInfo mapFileInfo = exportLanguage == ExportLanguageEnum.Chinese ? new FileInfo(@"inputCN.dat") : new FileInfo(@"inputEN.data"); if (!mapFileInfo.Exists) { throw new FileNotFoundException(string.Format("模板文件\"{0}\"不存在!", mapFileInfo.FullName)); } using (ExcelPackage xlsx = new ExcelPackage(mapFileInfo, true)) { ExcelWorksheet currentWorksheet = xlsx.Workbook.Worksheets.FirstOrDefault(); currentWorksheet.Name = "数据报告" + ExportDateTime.ToString("dd-M-yyyy hh-mm"); int insertRow = 5; //int insertColumn = 0; foreach (var bif in BIFList) { currentWorksheet.Cells[insertRow, 1].Value = bif.ArrayNo; currentWorksheet.Cells[insertRow, 2].Value = bif.PointNo; currentWorksheet.Cells[insertRow, 3].Value = bif.Height; currentWorksheet.Cells[insertRow, 4].Value = bif.Distance; if (exportLanguage == ExportLanguageEnum.Chinese) { currentWorksheet.Cells[insertRow, 5].Value = bif.StaffType == StaffTypeEnum.Upright ? "正尺" : "倒尺"; } currentWorksheet.Cells[insertRow, 6].Value = bif.ReferNo; currentWorksheet.Cells[insertRow, 7].Value = bif.MeasureType; currentWorksheet.Cells[insertRow, 8].Value = bif.IsReferNo; currentWorksheet.Cells[insertRow, 9].Value = bif.Elevation; //currentWorksheet.Cells[insertRow, 10].Value = bif.DesignElevation; //currentWorksheet.Cells[insertRow, 11].Value = bif.Cut; //currentWorksheet.Cells[insertRow, 12].Value = bif.Fill; // 如果为B测,输出时 B测点没有高差 if (bif.MeasureType != MeasureTypeEnum.B) { currentWorksheet.Cells[insertRow, 13].Value = bif.DeltaHeightDh; } insertRow += 1; } xlsx.SaveAs(new FileInfo(filePath)); return(true); } }
/// <summary> /// 保存数据到文件 /// </summary> /// <param name="filePath"></param> public void WriteData(string filePath) { XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); xmlDoc.AppendChild(xmlDecl); XmlNode xmlRoot = xmlDoc.CreateElement("", "wyl", ""); xmlDoc.AppendChild(xmlRoot); XmlNode xmlExportDataTimeNode = xmlDoc.CreateElement("ExportTime"); xmlExportDataTimeNode.InnerText = ExportDateTime.ToLongDateString(); xmlRoot.AppendChild(xmlExportDataTimeNode); foreach (var bif in BIFList) { XmlNode xmlPointNode = xmlDoc.CreateElement("Point"); XmlNode xmlArrayNo = xmlDoc.CreateElement("ArrayNo"); xmlArrayNo.InnerText = bif.ArrayNo.ToString(); xmlPointNode.AppendChild(xmlArrayNo); XmlNode xmlPointNo = xmlDoc.CreateElement("PointNo"); xmlPointNo.InnerText = bif.PointNo; xmlPointNode.AppendChild(xmlPointNo); XmlNode xmlHeightNode = xmlDoc.CreateElement("Height"); xmlHeightNode.InnerText = string.Format("{0:F6}", bif.Height); xmlPointNode.AppendChild(xmlHeightNode); XmlNode xmlDistanceNode = xmlDoc.CreateElement("Distance"); xmlDistanceNode.InnerText = string.Format("{0:F6}", bif.Distance); xmlPointNode.AppendChild(xmlDistanceNode); XmlNode xmlStaffTypeNode = xmlDoc.CreateElement("StaffType"); xmlStaffTypeNode.InnerText = Enum.GetName(typeof(StaffTypeEnum), bif.StaffType); xmlPointNode.AppendChild(xmlStaffTypeNode); XmlNode xmlReferNoNode = xmlDoc.CreateElement("ReferNo"); xmlReferNoNode.InnerText = bif.ReferNo; xmlPointNode.AppendChild(xmlReferNoNode); XmlNode xmlMeasureTypeNode = xmlDoc.CreateElement("MeasureType"); xmlMeasureTypeNode.InnerText = Enum.GetName(typeof(MeasureTypeEnum), bif.MeasureType); xmlPointNode.AppendChild(xmlMeasureTypeNode); XmlNode xmlIsReferNoNode = xmlDoc.CreateElement("IsReferNo"); xmlIsReferNoNode.InnerText = bif.IsReferNo; xmlPointNode.AppendChild(xmlIsReferNoNode); XmlNode xmlElevationNode = xmlDoc.CreateElement("Elevation"); xmlElevationNode.InnerText = string.Format("{0:F6}", bif.Elevation); xmlPointNode.AppendChild(xmlElevationNode); XmlNode xmlDesignElevationNode = xmlDoc.CreateElement("DesignElevation"); xmlDesignElevationNode.InnerText = string.Format("{0:F6}", bif.DesignElevation); xmlPointNode.AppendChild(xmlDesignElevationNode); XmlNode xmlCutNode = xmlDoc.CreateElement("Cut"); xmlCutNode.InnerText = string.Format("{0:F6}", bif.Cut); xmlPointNode.AppendChild(xmlCutNode); XmlNode xmlFillNode = xmlDoc.CreateElement("Fill"); xmlFillNode.InnerText = string.Format("{0:F6}", bif.Fill); xmlPointNode.AppendChild(xmlFillNode); XmlNode xmlDeltaHeightNode = xmlDoc.CreateElement("DeltaHeight"); xmlDeltaHeightNode.InnerText = string.Format("{0:F6}", bif.DeltaHeightDh); xmlPointNode.AppendChild(xmlDeltaHeightNode); xmlRoot.AppendChild(xmlPointNode); } xmlDoc.Save(filePath); }