forked from ddrilling/AsbCloudServer
Рефакторинг работы с excel
1. Использование новых методов расширения 2. Удалил неиспользуемый генератор файла DrillingProgramMaker 3. Поправлено название листа в ProcessMapReportTemplate
This commit is contained in:
parent
b686834236
commit
32a0678a56
@ -106,7 +106,7 @@ public class DailyReportExportService : IDailyReportExportService
|
||||
.GetExecutingAssembly()
|
||||
.GetTemplateCopyStreamAsync("DailyReportTemplate.xlsx", cancellationToken);
|
||||
|
||||
using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(excelTemplateStream);
|
||||
|
||||
AddDailyReportToWorkBook(workbook, dailyReport);
|
||||
|
||||
@ -120,18 +120,17 @@ public class DailyReportExportService : IDailyReportExportService
|
||||
{
|
||||
const string sheetName = "Суточный отчёт";
|
||||
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName)
|
||||
?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}.");
|
||||
var sheet = workbook.GetWorksheet(sheetName);;
|
||||
|
||||
sheet.Cell(cellCustomer).Value = dailyReport.Customer;
|
||||
sheet.Cell(cellContractor).Value = dailyReport.Contractor;
|
||||
sheet.Cell(cellDeposit).Value = dailyReport.Deposit;
|
||||
sheet.Cell(cellCluster).Value = dailyReport.Cluster;
|
||||
sheet.Cell(cellWellCaption).Value = dailyReport.WellCaption;
|
||||
sheet.Cell(cellWellType).Value = dailyReport.WellType;
|
||||
sheet.Cell(cellDate).Value = dailyReport.Date;
|
||||
sheet.Cell(cellDepthStart).Value = dailyReport.DepthStart;
|
||||
sheet.Cell(cellDepthEnd).Value = dailyReport.DepthEnd;
|
||||
sheet.Cell(cellCustomer).SetCellValue(dailyReport.Customer);
|
||||
sheet.Cell(cellContractor).SetCellValue(dailyReport.Contractor);
|
||||
sheet.Cell(cellDeposit).SetCellValue(dailyReport.Deposit);
|
||||
sheet.Cell(cellCluster).SetCellValue(dailyReport.Cluster);
|
||||
sheet.Cell(cellWellCaption).SetCellValue(dailyReport.WellCaption);
|
||||
sheet.Cell(cellWellType).SetCellValue(dailyReport.WellType);
|
||||
sheet.Cell(cellDate).SetCellValue(dailyReport.Date);
|
||||
sheet.Cell(cellDepthStart).SetCellValue(dailyReport.DepthStart);
|
||||
sheet.Cell(cellDepthEnd).SetCellValue(dailyReport.DepthEnd);
|
||||
|
||||
if (dailyReport.TimeBalanceBlock is not null)
|
||||
AddTimeBalanceBlockToSheet(sheet, dailyReport.TimeBalanceBlock);
|
||||
@ -150,10 +149,10 @@ public class DailyReportExportService : IDailyReportExportService
|
||||
|
||||
private static void AddTrajectoryBlockToSheet(IXLWorksheet sheet, TrajectoryBlockDto trajectoryBlock)
|
||||
{
|
||||
sheet.Cell(cellTrajectoryBlockWellboreDepth).Value = trajectoryBlock.WellboreDepth;
|
||||
sheet.Cell(cellTrajectoryBlockVerticalDepth).Value = trajectoryBlock.VerticalDepth;
|
||||
sheet.Cell(cellTrajectoryBlockZenithAngle).Value = trajectoryBlock.ZenithAngle;
|
||||
sheet.Cell(cellTrajectoryBlockAzimuthGeo).Value = trajectoryBlock.AzimuthGeo;
|
||||
sheet.Cell(cellTrajectoryBlockWellboreDepth).SetCellValue(trajectoryBlock.WellboreDepth);
|
||||
sheet.Cell(cellTrajectoryBlockVerticalDepth).SetCellValue(trajectoryBlock.VerticalDepth);
|
||||
sheet.Cell(cellTrajectoryBlockZenithAngle).SetCellValue(trajectoryBlock.ZenithAngle);
|
||||
sheet.Cell(cellTrajectoryBlockAzimuthGeo).SetCellValue(trajectoryBlock.AzimuthGeo);
|
||||
}
|
||||
|
||||
private static void AddTimeBalanceBlockToSheet(IXLWorksheet sheet, TimeBalanceBlockDto timeBalanceBlock)
|
||||
@ -162,19 +161,19 @@ public class DailyReportExportService : IDailyReportExportService
|
||||
|
||||
foreach (var wellOperation in timeBalanceBlock.WellOperations.OrderBy(w => w.IdWellOperation))
|
||||
{
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceDurationPlan).Value = wellOperation.DurationHours.Plan;
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceDurationFact).Value = wellOperation.DurationHours.Fact;
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceReasonDeviation).Value = wellOperation.ReasonDeviation;
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceDrillingDeviationPerSection).Value = wellOperation.DrillingDeviationPerSection;
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceDrillingDeviationPerDay).Value = wellOperation.DrillingDeviationPerDay;
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceDurationPlan).SetCellValue(wellOperation.DurationHours.Plan);
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceDurationFact).SetCellValue(wellOperation.DurationHours.Fact);
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceReasonDeviation).SetCellValue(wellOperation.ReasonDeviation);
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceDrillingDeviationPerSection).SetCellValue(wellOperation.DrillingDeviationPerSection);
|
||||
sheet.Cell(rowCurrent, columnTimeBalanceDrillingDeviationPerDay).SetCellValue(wellOperation.DrillingDeviationPerDay);
|
||||
|
||||
rowCurrent++;
|
||||
}
|
||||
|
||||
sheet.Cell(cellTimeBalanceBlockSection).Value = timeBalanceBlock.SectionName;
|
||||
sheet.Cell(cellTimeBalanceBlockWellDepthPlan).Value = timeBalanceBlock.WellDepth.Plan;
|
||||
sheet.Cell(cellTimeBalanceBlockWellDepthFact).Value = timeBalanceBlock.WellDepth.Fact;
|
||||
sheet.Cell(cellTimeBalanceBlockWellOperationSlipsTimeCount).Value = timeBalanceBlock.WellOperationSlipsTimeCount;
|
||||
sheet.Cell(cellTimeBalanceBlockSection).SetCellValue(timeBalanceBlock.SectionName);
|
||||
sheet.Cell(cellTimeBalanceBlockWellDepthPlan).SetCellValue(timeBalanceBlock.WellDepth.Plan);
|
||||
sheet.Cell(cellTimeBalanceBlockWellDepthFact).SetCellValue(timeBalanceBlock.WellDepth.Fact);
|
||||
sheet.Cell(cellTimeBalanceBlockWellOperationSlipsTimeCount).SetCellValue(timeBalanceBlock.WellOperationSlipsTimeCount);
|
||||
}
|
||||
|
||||
private static void AddSubsystemBlockToSheet(IXLWorksheet sheet, SubsystemBlockDto subsystemBlock)
|
||||
@ -183,24 +182,23 @@ public class DailyReportExportService : IDailyReportExportService
|
||||
|
||||
foreach (var subsystem in subsystemBlock.Subsystems)
|
||||
{
|
||||
sheet.Cell(rowСurrent, columnSubsystemName).Value = subsystem.Name;
|
||||
sheet.Cell(rowСurrent, columnSubsystemName).SetCellValue(subsystem.Name);
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerDayUsedTimeHours).SetCellValue(subsystem.UsagePerDay?.UsedTimeHours);
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerDaySumDepthInterval).SetCellValue(subsystem.UsagePerDay?.SumDepthInterval);
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerDayKUsage).SetCellValue(subsystem.UsagePerDay?.KUsage);
|
||||
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerDayUsedTimeHours).Value = subsystem.UsagePerDay?.UsedTimeHours;
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerDaySumDepthInterval).Value = subsystem.UsagePerDay?.SumDepthInterval;
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerDayKUsage).Value = subsystem.UsagePerDay?.KUsage;
|
||||
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerWellUsedTimeHours).Value = subsystem.UsagePerWell?.UsedTimeHours;
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerWellSumDepthInterval).Value = subsystem.UsagePerWell?.SumDepthInterval;
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerWellKUsage).Value = subsystem.UsagePerWell?.KUsage;
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerWellUsedTimeHours).SetCellValue(subsystem.UsagePerWell?.UsedTimeHours);
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerWellSumDepthInterval).SetCellValue(subsystem.UsagePerWell?.SumDepthInterval);
|
||||
sheet.Cell(rowСurrent, columnUseSubsystemPerWellKUsage).SetCellValue(subsystem.UsagePerWell?.KUsage);
|
||||
|
||||
rowСurrent++;
|
||||
}
|
||||
|
||||
sheet.Cell(cellSubsystemComment).Value = subsystemBlock.Comment;
|
||||
sheet.Cell(cellSubsystemTvgLagDays).Value = subsystemBlock.TvgLagDays;
|
||||
sheet.Cell(cellSubsystemMeasurementsPerDay).Value = subsystemBlock.MeasurementsPerDay;
|
||||
sheet.Cell(cellSubsystemWellbore).Value = subsystemBlock.Wellbore;
|
||||
sheet.Cell(cellSubsystemTotalRopPlan).Value = subsystemBlock.TotalRopPlan;
|
||||
sheet.Cell(cellSubsystemComment).SetCellValue(subsystemBlock.Comment);
|
||||
sheet.Cell(cellSubsystemTvgLagDays).SetCellValue(subsystemBlock.TvgLagDays);
|
||||
sheet.Cell(cellSubsystemMeasurementsPerDay).SetCellValue(subsystemBlock.MeasurementsPerDay);
|
||||
sheet.Cell(cellSubsystemWellbore).SetCellValue(subsystemBlock.Wellbore);
|
||||
sheet.Cell(cellSubsystemTotalRopPlan).SetCellValue(subsystemBlock.TotalRopPlan);
|
||||
}
|
||||
|
||||
private static void AddScheduleBlockToSheet(IXLWorksheet sheet, IEnumerable<ScheduleRecordDto> scheduleBlock)
|
||||
@ -209,9 +207,9 @@ public class DailyReportExportService : IDailyReportExportService
|
||||
|
||||
foreach (var schedule in scheduleBlock.OrderBy(s => s.ShiftStart))
|
||||
{
|
||||
sheet.Cell(rowCurrent, columnSheduleDriller).Value = $"{schedule.Surname} {schedule.Name} {schedule.Patronymic}";
|
||||
sheet.Cell(rowCurrent, columnSheduleShiftStart).Value = schedule.ShiftStart;
|
||||
sheet.Cell(rowCurrent, columnSheduleShiftEnd).Value = schedule.ShiftEnd;
|
||||
sheet.Cell(rowCurrent, columnSheduleDriller).SetCellValue($"{schedule.Surname} {schedule.Name} {schedule.Patronymic}");
|
||||
sheet.Cell(rowCurrent, columnSheduleShiftStart).SetCellValue(schedule.ShiftStart);
|
||||
sheet.Cell(rowCurrent, columnSheduleShiftEnd).SetCellValue(schedule.ShiftEnd);
|
||||
|
||||
rowCurrent++;
|
||||
}
|
||||
@ -224,11 +222,11 @@ public class DailyReportExportService : IDailyReportExportService
|
||||
|
||||
foreach (var processMapWellDrilling in processMapWellDrillingBlock.OrderBy(p => p.DrillingMode))
|
||||
{
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockDrillingMode).Value = processMapWellDrilling.DrillingMode;
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockWellBoreDepth).Value = processMapWellDrilling.WellBoreDepth;
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockMechDrillingHours).Value = processMapWellDrilling.MechDrillingHours;
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockRopPlan).Value = processMapWellDrilling.Rop.Plan;
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockRopFact).Value = processMapWellDrilling.Rop.Fact;
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockDrillingMode).SetCellValue(processMapWellDrilling.DrillingMode);
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockWellBoreDepth).SetCellValue(processMapWellDrilling.WellBoreDepth);
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockMechDrillingHours).SetCellValue(processMapWellDrilling.MechDrillingHours);
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockRopPlan).SetCellValue(processMapWellDrilling.Rop.Plan);
|
||||
sheet.Cell(rowCurrent, columnProcessMapWellDrillingBlockRopFact).SetCellValue(processMapWellDrilling.Rop.Fact);
|
||||
|
||||
rowCurrent++;
|
||||
}
|
||||
@ -238,12 +236,12 @@ public class DailyReportExportService : IDailyReportExportService
|
||||
{
|
||||
var rowCurrent = rowStartFactWellOperationBlock;
|
||||
|
||||
sheet.Cell(cellSectionDrillingHours).Value = factWellOperationBlock.SectionDrillingHours;
|
||||
sheet.Cell(cellSectionDrillingHours).SetCellValue(factWellOperationBlock.SectionDrillingHours);
|
||||
|
||||
foreach (var factOperation in factWellOperationBlock.WellOperations.OrderBy(w => w.CategoryName))
|
||||
{
|
||||
sheet.Cell(rowCurrent, columnWellOperationCategory).Value = factOperation.CategoryName;
|
||||
sheet.Cell(rowCurrent, columnWellOperationDurationHours).Value = factOperation.DurationHours;
|
||||
sheet.Cell(rowCurrent, columnWellOperationCategory).SetCellValue(factOperation.CategoryName);
|
||||
sheet.Cell(rowCurrent, columnWellOperationDurationHours).SetCellValue(factOperation.DurationHours);
|
||||
|
||||
rowCurrent++;
|
||||
}
|
||||
@ -251,7 +249,7 @@ public class DailyReportExportService : IDailyReportExportService
|
||||
|
||||
private static void AddSignBlockToSheet(IXLWorksheet sheet, SignBlockDto signBlock)
|
||||
{
|
||||
sheet.Cell(cellSignDrillingMaster).Value = signBlock.DrillingMaster?.ToString();
|
||||
sheet.Cell(cellSignSupervisor).Value = signBlock.Supervisor?.ToString();
|
||||
sheet.Cell(cellSignDrillingMaster).SetCellValue(signBlock.DrillingMaster?.ToString());
|
||||
sheet.Cell(cellSignSupervisor).SetCellValue(signBlock.Supervisor?.ToString());
|
||||
}
|
||||
}
|
@ -42,8 +42,9 @@ public class DetectedOperationExportService
|
||||
private const int columnIdReasonOfEnd = 9;
|
||||
private const int columnComment = 10;
|
||||
|
||||
//TODO: удалить неиспользуемую зависимость
|
||||
private readonly IAsbCloudDbContext dbContext;
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
|
||||
public DetectedOperationExportService(IAsbCloudDbContext dbContext, IWellOperationRepository wellOperationRepository)
|
||||
{
|
||||
@ -82,7 +83,7 @@ public class DetectedOperationExportService
|
||||
{
|
||||
using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken);
|
||||
|
||||
using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(excelTemplateStream);
|
||||
|
||||
await AddToWorkbookAsync(workbook, well, host, operationDetectorResults, cancellationToken);
|
||||
|
||||
@ -100,8 +101,7 @@ public class DetectedOperationExportService
|
||||
if (!operationDetectorResults.Any())
|
||||
return;
|
||||
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName)
|
||||
?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}.");
|
||||
var sheet = workbook.GetWorksheet(sheetName);
|
||||
|
||||
await AddToSheetAsync(sheet, well, host, operationDetectorResults
|
||||
.OrderBy(x => x.Operation.DateStart).ThenBy(x => x.Operation.DepthStart).ToArray(),
|
||||
@ -113,10 +113,10 @@ public class DetectedOperationExportService
|
||||
{
|
||||
var wellOperationCategories = await dbContext.WellOperationCategories.ToListAsync(cancellationToken);
|
||||
|
||||
sheet.Cell(cellDepositName).Value = well.Cluster.Deposit.Caption;
|
||||
sheet.Cell(cellClusterName).Value = well.Cluster.Caption;
|
||||
sheet.Cell(cellWellName).Value = well.Caption;
|
||||
sheet.Cell(cellDeltaDate).Value = operationDetectorResults.Max(o => o.Operation.DateEnd) - operationDetectorResults.Min(o => o.Operation.DateStart);
|
||||
sheet.Cell(cellDepositName).SetCellValue(well.Cluster.Deposit.Caption);
|
||||
sheet.Cell(cellClusterName).SetCellValue(well.Cluster.Caption);
|
||||
sheet.Cell(cellWellName).SetCellValue(well.Caption);
|
||||
sheet.Cell(cellDeltaDate).SetCellValue(operationDetectorResults.Max(o => o.Operation.DateEnd) - operationDetectorResults.Min(o => o.Operation.DateStart));
|
||||
|
||||
var detectedOperations = operationDetectorResults.Select(o => o.Operation).ToArray();
|
||||
|
||||
@ -128,31 +128,38 @@ public class DetectedOperationExportService
|
||||
|
||||
var row = sheet.Row(5 + i + headerRowsCount);
|
||||
|
||||
row.Cell(columnOperationName).Value = GetCategoryName(wellOperationCategories, current);
|
||||
row.Cell(columnDateEnd).Value = dateEnd;
|
||||
row.Cell(columnDuration).Value = (dateEnd - dateStart).TotalMinutes;
|
||||
row.Cell(columnDepthStart).Value = current.DepthStart;
|
||||
row.Cell(columnDepthEnd).Value = current.DepthEnd;
|
||||
row.Cell(columnDepth).Value = current.DepthEnd - current.DepthStart;
|
||||
var categoryName = GetCategoryName(wellOperationCategories, current);
|
||||
|
||||
row.Cell(columnOperationName).SetCellValue(categoryName);
|
||||
row.Cell(columnDateEnd).SetCellValue(dateEnd);
|
||||
row.Cell(columnDuration).SetCellValue((dateEnd - dateStart).TotalMinutes);
|
||||
row.Cell(columnDepthStart).SetCellValue(current.DepthStart);
|
||||
row.Cell(columnDepthEnd).SetCellValue(current.DepthEnd);
|
||||
row.Cell(columnDepth).SetCellValue(current.DepthEnd - current.DepthStart);
|
||||
|
||||
if (current.ExtraData.TryGetValue("IdReasonOfEnd", out object? idReasonOfEndObject)
|
||||
&& idReasonOfEndObject is int idReasonOfEnd)
|
||||
row.Cell(columnIdReasonOfEnd).Value = GetIdReasonOfEnd(idReasonOfEnd);
|
||||
{
|
||||
var reasonOfEnd = GetIdReasonOfEnd(idReasonOfEnd);
|
||||
row.Cell(columnIdReasonOfEnd).SetCellValue(reasonOfEnd);
|
||||
}
|
||||
|
||||
var query = new QueryBuilder();
|
||||
query.Add("end", dateStart.AddSeconds(1800 * 0.9).ToString("yyyy-MM-ddTHH:mm:ss.fff"));
|
||||
query.Add("range", "1800");
|
||||
|
||||
row.Cell(columnDateStart).SetCellValue(dateStart);
|
||||
|
||||
var link = $"{host}/well/{well.Id}/telemetry/monitoring{query}";
|
||||
row.Cell(columnDateStart).SetHyperlink(link);
|
||||
|
||||
row.Cell(columnDateStart).Value = dateStart;
|
||||
row.Cell(columnDateStart).SetHyperlink(new XLHyperlink(link));
|
||||
|
||||
row.Cell(columnDeltaDepth).Value = i > 0 && i + 1 < detectedOperations.Length
|
||||
var deltaDepth = i > 0 && i + 1 < detectedOperations.Length
|
||||
? current.DepthStart - detectedOperations[i - 1].DepthEnd
|
||||
: 0;
|
||||
row.Cell(columnDeltaDepth).SetCellValue(deltaDepth);
|
||||
|
||||
row.Cell(columnComment).Value = CreateComment(operationDetectorResults[i]);
|
||||
var comment = CreateComment(operationDetectorResults[i]);
|
||||
row.Cell(columnComment).SetCellValue(comment);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using AsbCloudApp.Data.DrillTestReport;
|
||||
using AsbCloudApp.Services;
|
||||
using ClosedXML.Excel;
|
||||
using System;
|
||||
using System.IO;
|
||||
@ -7,6 +6,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DrillTestReport
|
||||
{
|
||||
@ -20,7 +20,7 @@ namespace AsbCloudInfrastructure.Services.DrillTestReport
|
||||
{
|
||||
using var excelTemplateStream = await Assembly.GetExecutingAssembly().GetTemplateCopyStreamAsync(templateName, cancellationToken);
|
||||
|
||||
using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(excelTemplateStream);
|
||||
|
||||
AddToWorkbook(workbook, report);
|
||||
|
||||
@ -31,49 +31,38 @@ namespace AsbCloudInfrastructure.Services.DrillTestReport
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
|
||||
private void AddToWorkbook(XLWorkbook workbook, DrillTestReportDataDto report)
|
||||
{
|
||||
var drillTestEntities = report.Data.Params;
|
||||
if (!drillTestEntities.Any())
|
||||
var drillTests = report.Data.Params;
|
||||
|
||||
if (!drillTests.Any())
|
||||
return;
|
||||
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName)
|
||||
?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}.");
|
||||
var sheet = workbook.GetWorksheet(sheetName);
|
||||
|
||||
sheet.Cell(4, 2).Value = report.Caption;
|
||||
sheet.Cell(5, 2)._SetValue(report.Date, setAllBorders: false);
|
||||
sheet.Cell(4, 2).SetCellValue(report.Caption);
|
||||
sheet.Cell(5, 2).SetCellValue(report.Date);
|
||||
|
||||
var rowNumber = startRowNumber;
|
||||
|
||||
var stepWithMaxDepthSpeed = drillTestEntities.OrderByDescending(p => p.DepthSpeed).FirstOrDefault()!.Step;
|
||||
var stepWithMaxDepthSpeed = drillTests.MaxBy(p => p.DepthSpeed)!.Step;
|
||||
var startDepth = report.Data.DepthStart;
|
||||
var startDate = report.Data.TimeStampStart;
|
||||
|
||||
foreach (var drillTestEntity in drillTestEntities)
|
||||
var rowNumber = startRowNumber;
|
||||
|
||||
foreach (var drillTestEntity in drillTests)
|
||||
{
|
||||
var endDepth = startDepth + (drillTestEntity.DepthDrillStep ?? 0);
|
||||
var endDateTime = startDate.AddSeconds(drillTestEntity.TimeDrillStep ?? 0);
|
||||
|
||||
sheet.Cell(rowNumber, 2).Value = startDepth;
|
||||
|
||||
sheet.Cell(rowNumber, 3).Value = endDepth;
|
||||
|
||||
sheet.Cell(rowNumber, 4).Value = drillTestEntity.DepthDrillStep;
|
||||
|
||||
sheet.Cell(rowNumber, 5).Value = drillTestEntity.Workload;
|
||||
|
||||
sheet.Cell(rowNumber, 6).Value = drillTestEntity.Speed;
|
||||
|
||||
var cell = sheet.Cell(rowNumber, 7);
|
||||
cell._SetValue(startDate.DateTime);
|
||||
|
||||
cell = sheet.Cell(rowNumber, 8);
|
||||
cell._SetValue(endDateTime.DateTime);
|
||||
|
||||
sheet.Cell(rowNumber, 9).Value = Math.Round((drillTestEntity.TimeDrillStep ?? 0) / (60 * 60), 2);
|
||||
|
||||
sheet.Cell(rowNumber, 10).Value = drillTestEntity.DepthSpeed;
|
||||
sheet.Cell(rowNumber, 2).SetCellValue(startDepth);
|
||||
sheet.Cell(rowNumber, 3).SetCellValue(endDepth);
|
||||
sheet.Cell(rowNumber, 4).SetCellValue(drillTestEntity.DepthDrillStep);
|
||||
sheet.Cell(rowNumber, 5).SetCellValue(drillTestEntity.Workload);
|
||||
sheet.Cell(rowNumber, 6).SetCellValue(drillTestEntity.Speed);
|
||||
sheet.Cell(rowNumber, 7).SetCellValue(startDate.DateTime);
|
||||
sheet.Cell(rowNumber, 8).SetCellValue(endDateTime.DateTime);
|
||||
sheet.Cell(rowNumber, 9).SetCellValue(Math.Round((drillTestEntity.TimeDrillStep ?? 0) / (60 * 60), 2));
|
||||
sheet.Cell(rowNumber, 10).SetCellValue(drillTestEntity.DepthSpeed);
|
||||
|
||||
if (drillTestEntity.Step == stepWithMaxDepthSpeed)
|
||||
{
|
||||
|
@ -1,133 +0,0 @@
|
||||
using ClosedXML.Excel;
|
||||
using ClosedXML.Excel.Drawings;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
{
|
||||
|
||||
internal class DrillingProgramMaker
|
||||
{
|
||||
private const int maxAllowedColumns = 256;
|
||||
|
||||
public static void UniteExcelFiles(IEnumerable<string> excelFilesNames, string resultExcelPath, IEnumerable<AsbCloudApp.Data.DrillingProgramPartDto> parts, AsbCloudApp.Data.WellDto well)
|
||||
{
|
||||
var resultExcelFile = new XLWorkbook(XLEventTracking.Disabled);
|
||||
|
||||
var titleSheet = resultExcelFile.AddWorksheet("Титульный лист");
|
||||
var marks = parts.SelectMany(p => p.File!.FileMarks);
|
||||
var titleSheetMaker = new TitleListSheet(marks, well);
|
||||
titleSheetMaker.Draw(titleSheet);
|
||||
|
||||
var contentSheet = resultExcelFile.AddWorksheet("Содержание");
|
||||
var contentListSheetMaker = new ContentListSheet(parts);
|
||||
contentListSheetMaker.Draw(contentSheet);
|
||||
|
||||
var filteredFileNames = excelFilesNames.Distinct();
|
||||
|
||||
foreach (var excelFileName in filteredFileNames)
|
||||
{
|
||||
using var workbookSrc = new XLWorkbook(excelFileName, XLEventTracking.Disabled);
|
||||
|
||||
foreach (var sheet in workbookSrc.Worksheets)
|
||||
{
|
||||
if (sheet.Visibility == XLWorksheetVisibility.Visible)
|
||||
CopySheet(resultExcelFile, sheet);
|
||||
}
|
||||
}
|
||||
|
||||
resultExcelFile.SaveAs(resultExcelPath,
|
||||
new SaveOptions { EvaluateFormulasBeforeSaving = true });
|
||||
}
|
||||
|
||||
private static void CopySheet(XLWorkbook workbookDst, IXLWorksheet sheetSrc)
|
||||
{
|
||||
var newSheetName = sheetSrc.Name;
|
||||
var suffix = "";
|
||||
int index = 1;
|
||||
|
||||
while (workbookDst.Worksheets.Contains(newSheetName))
|
||||
{
|
||||
newSheetName = sheetSrc.Name;
|
||||
suffix = $"_{index++}";
|
||||
if (newSheetName.Length + suffix.Length >= 31)
|
||||
newSheetName = newSheetName[..(31 - suffix.Length)];
|
||||
newSheetName += suffix;
|
||||
}
|
||||
|
||||
var imagesInfos = sheetSrc.Pictures.Select(p => new ImageInfo
|
||||
{
|
||||
Id = p.Id,
|
||||
Data = p.ImageStream.GetBuffer(),
|
||||
Height = p.Height,
|
||||
Width = p.Width,
|
||||
TopLeftCellAddress = p.TopLeftCell.Address,
|
||||
Left = p.Left,
|
||||
Top = p.Top
|
||||
}).ToList();
|
||||
|
||||
IXLWorksheet resultSheet;
|
||||
|
||||
if (sheetSrc.Columns().Count() > maxAllowedColumns)
|
||||
{
|
||||
resultSheet = workbookDst.Worksheets.Add(newSheetName);
|
||||
|
||||
var rngData = GetCellsRange(sheetSrc);
|
||||
|
||||
rngData.CopyTo(resultSheet.Cell(1, 1));
|
||||
|
||||
var lastRowWithData = rngData.LastRowUsed().RangeAddress
|
||||
.LastAddress.RowNumber;
|
||||
|
||||
for (int i = 1; i < lastRowWithData; i++)
|
||||
{
|
||||
resultSheet.Row(i).Height = sheetSrc.Row(i).Height;
|
||||
resultSheet.Column(i).Width = sheetSrc.Column(i).Width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RemovePicturesFromSheet(sheetSrc);
|
||||
resultSheet = sheetSrc.CopyTo(workbookDst, newSheetName);
|
||||
}
|
||||
CopyImagesToAnotherSheet(imagesInfos, resultSheet);
|
||||
}
|
||||
|
||||
private static IXLWorksheet CopyImagesToAnotherSheet(IEnumerable<ImageInfo> imagesInfos,
|
||||
IXLWorksheet resultSheet)
|
||||
{
|
||||
foreach (var image in imagesInfos)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
stream.Write(image.Data, 0, image.Data.Length);
|
||||
|
||||
resultSheet.AddPicture(stream)
|
||||
.WithPlacement(XLPicturePlacement.Move)
|
||||
.WithSize(image.Width, image.Height)
|
||||
.MoveTo(resultSheet.Cell(image.TopLeftCellAddress),
|
||||
image.Left, image.Top);
|
||||
}
|
||||
|
||||
return resultSheet;
|
||||
}
|
||||
|
||||
private static void RemovePicturesFromSheet(IXLWorksheet sheet)
|
||||
{
|
||||
var filteredPics = sheet.Pictures.Select(p => p.Name).Distinct().ToList();
|
||||
|
||||
foreach (var n in filteredPics)
|
||||
sheet.Pictures.Delete(n);
|
||||
}
|
||||
|
||||
private static IXLRange GetCellsRange(IXLWorksheet sheet)
|
||||
{
|
||||
var firstTableCell = sheet.FirstCellUsed();
|
||||
var lastTableCell = sheet.LastCellUsed();
|
||||
var rngData = sheet.Range(firstTableCell.Address, lastTableCell.Address);
|
||||
|
||||
return rngData;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
@ -37,7 +37,7 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr
|
||||
return null;
|
||||
|
||||
var stream = GetExcelTemplateStream();
|
||||
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(stream);
|
||||
|
||||
var data = await processMapReportWellDrillingService.GetAsync(idWell, cancellationToken);
|
||||
|
||||
@ -55,9 +55,10 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr
|
||||
private static void FillProcessMapToWorkbook(XLWorkbook workbook,
|
||||
IEnumerable<ProcessMapReportWellDrillingDto> data)
|
||||
{
|
||||
var sheet = workbook.Worksheets.FirstOrDefault();
|
||||
if (sheet is null)
|
||||
return;
|
||||
const string sheetName = "Отчёт";
|
||||
|
||||
var sheet = workbook.GetWorksheet(sheetName);
|
||||
|
||||
var dataBySections = data.GroupBy(p => p.IdWellSectionType);
|
||||
FillSheet(sheet, dataBySections);
|
||||
}
|
||||
@ -83,7 +84,7 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr
|
||||
sheet.Range(row, firstColumn, row, lastColumn)
|
||||
.Merge()
|
||||
.FirstCell()
|
||||
.SetVal(sectionName)
|
||||
.SetCellValue(sectionName)
|
||||
.Style
|
||||
.Fill.SetBackgroundColor(XLColor.LightGray);
|
||||
row++;
|
||||
@ -102,17 +103,10 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr
|
||||
const int columnRopTime = firstColumn + 3;
|
||||
const int columnMode = firstColumn + 4;
|
||||
|
||||
sheet.Cell(row, firstColumn)
|
||||
.SetVal(interval.DepthStart, "0.0");
|
||||
|
||||
sheet.Cell(row, columnDepth)
|
||||
.SetVal(interval.DepthEnd, "0.0");
|
||||
|
||||
sheet.Cell(row, columnDate)
|
||||
.SetVal(interval.DateStart);
|
||||
|
||||
sheet.Cell(row, columnRopTime)
|
||||
.SetVal(interval.MechDrillingHours);
|
||||
sheet.Cell(row, firstColumn).SetCellValue(interval.DepthStart);
|
||||
sheet.Cell(row, columnDepth).SetCellValue(interval.DepthEnd);
|
||||
sheet.Cell(row, columnDate).SetCellValue(interval.DateStart);
|
||||
sheet.Cell(row, columnRopTime).SetCellValue(interval.MechDrillingHours);
|
||||
|
||||
row = FillIntervalModeData(sheet, interval, columnMode, row);
|
||||
|
||||
@ -131,25 +125,18 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr
|
||||
int columnUsageFact = columnUsagePlan + 1;
|
||||
int columnRop = columnUsageFact + 12;
|
||||
|
||||
sheet.Cell(row, column)
|
||||
.SetVal(modeData.DrillingMode);
|
||||
sheet.Cell(row, column).SetCellValue(modeData.DrillingMode);
|
||||
|
||||
sheet.Cell(row, columnDeltaDepth)
|
||||
.SetVal(modeData.DeltaDepth);
|
||||
sheet.Cell(row, columnDeltaDepth).SetCellValue(modeData.DeltaDepth);
|
||||
|
||||
FillIntervalModeDataParam(sheet, modeData.PressureDiff, columnPressure, row);
|
||||
FillIntervalModeDataParam(sheet, modeData.AxialLoad, columnLoad, row);
|
||||
FillIntervalModeDataParam(sheet, modeData.TopDriveTorque, columnTorque, row);
|
||||
FillIntervalModeDataSpeed(sheet, modeData.SpeedLimit, columnSpeed, row);
|
||||
|
||||
sheet.Cell(row, columnUsagePlan)
|
||||
.SetVal(modeData.UsagePlan);
|
||||
|
||||
sheet.Cell(row, columnUsageFact)
|
||||
.SetVal(modeData.UsageFact);
|
||||
|
||||
sheet.Cell(row, columnRop)
|
||||
.SetVal(modeData.Rop.Fact);
|
||||
sheet.Cell(row, columnUsagePlan).SetCellValue(modeData.UsagePlan);
|
||||
sheet.Cell(row, columnUsageFact).SetCellValue(modeData.UsageFact);
|
||||
sheet.Cell(row, columnRop).SetCellValue(modeData.Rop.Fact);
|
||||
|
||||
return row + 1;
|
||||
}
|
||||
@ -163,20 +150,11 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr
|
||||
const int columnOffsetLimit = 3;
|
||||
const int columnOffsetPercent = 4;
|
||||
|
||||
sheet.Cell(row, column + columnOffsetSpPlan)
|
||||
.SetVal(dataParam.SetpointPlan);
|
||||
|
||||
sheet.Cell(row, column + columnOffsetSpFact)
|
||||
.SetVal(dataParam.SetpointFact);
|
||||
|
||||
sheet.Cell(row, column + columnOffsetFact)
|
||||
.SetVal(dataParam.Fact);
|
||||
|
||||
sheet.Cell(row, column + columnOffsetLimit)
|
||||
.SetVal(dataParam.Limit);
|
||||
|
||||
sheet.Cell(row, column + columnOffsetPercent)
|
||||
.SetVal(dataParam.SetpointUsage, format: "0.0");
|
||||
sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(dataParam.SetpointPlan);
|
||||
sheet.Cell(row, column + columnOffsetSpFact).SetCellValue(dataParam.SetpointFact);
|
||||
sheet.Cell(row, column + columnOffsetFact).SetCellValue(dataParam.Fact);
|
||||
sheet.Cell(row, column + columnOffsetLimit).SetCellValue(dataParam.Limit);
|
||||
sheet.Cell(row, column + columnOffsetPercent).SetCellValue(dataParam.SetpointUsage);
|
||||
}
|
||||
|
||||
private static void FillIntervalModeDataSpeed(IXLWorksheet sheet,
|
||||
@ -188,22 +166,14 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr
|
||||
const int columnOffsetLimit = 3;
|
||||
const int columnOffsetPercent = 4;
|
||||
|
||||
sheet.Cell(row, column + columnOffsetSpPlan)
|
||||
.SetVal(dataParam.SetpointPlan);
|
||||
|
||||
sheet.Cell(row, column + columnOffsetSpFact)
|
||||
.SetVal(dataParam.SetpointFact);
|
||||
|
||||
sheet.Cell(row, column + columnOffsetFact)
|
||||
.SetVal(dataParam.Fact);
|
||||
|
||||
sheet.Cell(row, column + columnOffsetLimit)
|
||||
.SetVal(dataParam.Limit);
|
||||
|
||||
sheet.Cell(row, column + columnOffsetPercent)
|
||||
.SetVal(dataParam.SetpointUsage, format: "0.0");
|
||||
sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(dataParam.SetpointPlan);
|
||||
sheet.Cell(row, column + columnOffsetSpFact).SetCellValue(dataParam.SetpointFact);
|
||||
sheet.Cell(row, column + columnOffsetFact).SetCellValue(dataParam.Fact);
|
||||
sheet.Cell(row, column + columnOffsetLimit).SetCellValue(dataParam.Limit);
|
||||
sheet.Cell(row, column + columnOffsetPercent).SetCellValue(dataParam.SetpointUsage);
|
||||
}
|
||||
|
||||
//TODO: использовать метод расширения, избавиться от этого метода
|
||||
private static Stream GetExcelTemplateStream()
|
||||
{
|
||||
var stream = Assembly.GetExecutingAssembly()
|
||||
@ -213,6 +183,7 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr
|
||||
return stream!;
|
||||
}
|
||||
|
||||
//TODO: нужен ли этот метод? Это можно настроить в шаблоне
|
||||
private static void SetBorders(IXLStyle style)
|
||||
{
|
||||
style.Border.RightBorder = XLBorderStyleValues.Thin;
|
||||
|
@ -28,7 +28,7 @@ public class ProcessMapPlanImportWellDrillingService : IProcessMapPlanImportServ
|
||||
|
||||
private const int headerRowsCount = 2;
|
||||
|
||||
private const int columnWellSectionType = 1;
|
||||
private const int columnSection = 1;
|
||||
private const int columnMode = 2;
|
||||
private const int columnDepthStart = 3;
|
||||
private const int columnDepthEnd = 4;
|
||||
@ -116,8 +116,7 @@ public class ProcessMapPlanImportWellDrillingService : IProcessMapPlanImportServ
|
||||
|
||||
private void AddToWorkbook(XLWorkbook workbook, IEnumerable<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillings)
|
||||
{
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlan)
|
||||
?? throw new FileFormatException($"Книга excel не содержит листа {sheetNamePlan}.");
|
||||
var sheet = workbook.GetWorksheet(sheetNamePlan);
|
||||
|
||||
AddToSheet(sheet, processMapPlanWellDrillings.ToArray());
|
||||
}
|
||||
@ -136,31 +135,32 @@ public class ProcessMapPlanImportWellDrillingService : IProcessMapPlanImportServ
|
||||
|
||||
private void AddToRow(IXLRow row, ProcessMapPlanWellDrillingDto processMapPlanWellDrillings)
|
||||
{
|
||||
row.Cell(columnWellSectionType).Value = sections.First(x => x.Id == processMapPlanWellDrillings.IdWellSectionType).Caption;
|
||||
row.Cell(columnMode).Value = GetModeCaption(processMapPlanWellDrillings.IdMode);
|
||||
row.Cell(columnDepthStart).Value = processMapPlanWellDrillings.DepthStart;
|
||||
row.Cell(columnDepthEnd).Value = processMapPlanWellDrillings.DepthEnd;
|
||||
row.Cell(columnPressurePlan).Value = processMapPlanWellDrillings.Pressure.Plan;
|
||||
row.Cell(columnPressureLimitMax).Value = processMapPlanWellDrillings.Pressure.LimitMax;
|
||||
row.Cell(columnAxialLoadPlan).Value = processMapPlanWellDrillings.AxialLoad.Plan;
|
||||
row.Cell(columnAxialLoadLimitMax).Value = processMapPlanWellDrillings.AxialLoad.LimitMax;
|
||||
row.Cell(columnTopDriveTorquePlan).Value = processMapPlanWellDrillings.TopDriveTorque.Plan;
|
||||
row.Cell(columnTopDriveTorqueLimitMax).Value = processMapPlanWellDrillings.TopDriveTorque.LimitMax;
|
||||
row.Cell(columnTopDriveSpeedPlan).Value = processMapPlanWellDrillings.TopDriveSpeed.Plan;
|
||||
row.Cell(columnTopDriveSpeedLimitMax).Value = processMapPlanWellDrillings.TopDriveSpeed.LimitMax;
|
||||
row.Cell(columnFlowPlan).Value = processMapPlanWellDrillings.Flow.Plan;
|
||||
row.Cell(columnFlowLimitMax).Value = processMapPlanWellDrillings.Flow.LimitMax;
|
||||
row.Cell(columnRopPlan).Value = processMapPlanWellDrillings.RopPlan;
|
||||
row.Cell(columnUsageSaub).Value = processMapPlanWellDrillings.UsageSaub;
|
||||
row.Cell(columnUsageSpin).Value = processMapPlanWellDrillings.UsageSpin;
|
||||
row.Cell(columnComment).Value = processMapPlanWellDrillings.Comment;
|
||||
var section = sections.First(x => x.Id == processMapPlanWellDrillings.IdWellSectionType).Caption;
|
||||
var modeCaption = GetModeCaption(processMapPlanWellDrillings.IdMode);
|
||||
|
||||
row.Cell(columnSection).SetCellValue(section);
|
||||
row.Cell(columnMode).SetCellValue(modeCaption);
|
||||
row.Cell(columnDepthStart).SetCellValue(processMapPlanWellDrillings.DepthStart);
|
||||
row.Cell(columnDepthEnd).SetCellValue(processMapPlanWellDrillings.DepthEnd);
|
||||
row.Cell(columnPressurePlan).SetCellValue(processMapPlanWellDrillings.Pressure.Plan);
|
||||
row.Cell(columnPressureLimitMax).SetCellValue(processMapPlanWellDrillings.Pressure.LimitMax);
|
||||
row.Cell(columnAxialLoadPlan).SetCellValue(processMapPlanWellDrillings.AxialLoad.Plan);
|
||||
row.Cell(columnAxialLoadLimitMax).SetCellValue(processMapPlanWellDrillings.AxialLoad.LimitMax);
|
||||
row.Cell(columnTopDriveTorquePlan).SetCellValue(processMapPlanWellDrillings.TopDriveTorque.Plan);
|
||||
row.Cell(columnTopDriveTorqueLimitMax).SetCellValue(processMapPlanWellDrillings.TopDriveTorque.LimitMax);
|
||||
row.Cell(columnTopDriveSpeedPlan).SetCellValue(processMapPlanWellDrillings.TopDriveSpeed.Plan);
|
||||
row.Cell(columnTopDriveSpeedLimitMax).SetCellValue(processMapPlanWellDrillings.TopDriveSpeed.LimitMax);
|
||||
row.Cell(columnFlowPlan).SetCellValue(processMapPlanWellDrillings.Flow.Plan);
|
||||
row.Cell(columnFlowLimitMax).SetCellValue(processMapPlanWellDrillings.Flow.LimitMax);
|
||||
row.Cell(columnRopPlan).SetCellValue(processMapPlanWellDrillings.RopPlan);
|
||||
row.Cell(columnUsageSaub).SetCellValue(processMapPlanWellDrillings.UsageSaub);
|
||||
row.Cell(columnUsageSpin).SetCellValue(processMapPlanWellDrillings.UsageSpin);
|
||||
row.Cell(columnComment).SetCellValue(processMapPlanWellDrillings.Comment);
|
||||
}
|
||||
|
||||
private IEnumerable<ProcessMapPlanWellDrillingDto> ParseWorkBook(IXLWorkbook workbook)
|
||||
{
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlan)
|
||||
?? throw new FileFormatException($"Книга excel не содержит листа {sheetNamePlan}.");
|
||||
|
||||
var sheet = workbook.GetWorksheet(sheetNamePlan);
|
||||
return ParseSheet(sheet);
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ public class ProcessMapPlanImportWellDrillingService : IProcessMapPlanImportServ
|
||||
|
||||
private ProcessMapPlanWellDrillingDto ParseRow(IXLRow row)
|
||||
{
|
||||
var wellSectionTypeCaption = row.Cell(columnWellSectionType).GetCellValue<string>()?.Trim().ToLower();
|
||||
var wellSectionTypeCaption = row.Cell(columnSection).GetCellValue<string>()?.Trim().ToLower();
|
||||
var modeName = row.Cell(columnMode).GetCellValue<string>()?.Trim().ToLower();
|
||||
var depthStart = row.Cell(columnDepthStart).GetCellValue<double>();
|
||||
var depthEnd = row.Cell(columnDepthEnd).GetCellValue<double>();
|
||||
@ -337,7 +337,7 @@ public class ProcessMapPlanImportWellDrillingService : IProcessMapPlanImportServ
|
||||
{
|
||||
using var excelTemplateStream = (await GetExcelTemplateStreamAsync(cancellationToken)).File;
|
||||
|
||||
using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(excelTemplateStream);
|
||||
|
||||
AddToWorkbook(workbook, processMapPlanWellDrillings);
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Export
|
||||
private Stream MakeExelFileStream(IEnumerable<T> trajectories)
|
||||
{
|
||||
using Stream ecxelTemplateStream = GetTemplateFile();
|
||||
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(ecxelTemplateStream);
|
||||
AddTrajecoryToWorkbook(workbook, trajectories);
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
workbook.SaveAs(memoryStream, new SaveOptions { });
|
||||
@ -65,9 +65,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Export
|
||||
{
|
||||
if (trajectories.Any())
|
||||
{
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName);
|
||||
if (sheet is null)
|
||||
throw new FileFormatException($"Лист с именем {sheetName} отсутствует, либо имеет некорректное название");
|
||||
var sheet = workbook.GetWorksheet(sheetName);
|
||||
AddTrajecoryToSheet(sheet, trajectories);
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Export
|
||||
|
||||
protected override void AddCoordinatesToRow(IXLRow row, TrajectoryGeoFactDto trajectory)
|
||||
{
|
||||
row.Cell(1).Value = trajectory.WellboreDepth;
|
||||
row.Cell(2).Value = trajectory.ZenithAngle;
|
||||
row.Cell(3).Value = trajectory.AzimuthGeo;
|
||||
row.Cell(4).Value = trajectory.AzimuthMagnetic;
|
||||
row.Cell(5).Value = trajectory.VerticalDepth;
|
||||
row.Cell(6).Value = trajectory.Comment;
|
||||
row.Cell(1).SetCellValue(trajectory.WellboreDepth);
|
||||
row.Cell(2).SetCellValue(trajectory.ZenithAngle);
|
||||
row.Cell(3).SetCellValue(trajectory.AzimuthGeo);
|
||||
row.Cell(4).SetCellValue(trajectory.AzimuthMagnetic);
|
||||
row.Cell(5).SetCellValue(trajectory.VerticalDepth);
|
||||
row.Cell(6).SetCellValue(trajectory.Comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,12 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Export
|
||||
|
||||
protected override void AddCoordinatesToRow(IXLRow row, TrajectoryGeoFactDto trajectory)
|
||||
{
|
||||
row.Cell(1).Value = trajectory.WellboreDepth;
|
||||
row.Cell(2).Value = trajectory.ZenithAngle;
|
||||
row.Cell(3).Value = trajectory.AzimuthGeo;
|
||||
row.Cell(4).Value = trajectory.AzimuthMagnetic;
|
||||
row.Cell(5).Value = trajectory.VerticalDepth;
|
||||
row.Cell(6).Value = trajectory.Comment;
|
||||
row.Cell(1).SetCellValue(trajectory.WellboreDepth);
|
||||
row.Cell(2).SetCellValue(trajectory.ZenithAngle);
|
||||
row.Cell(3).SetCellValue(trajectory.AzimuthGeo);
|
||||
row.Cell(4).SetCellValue(trajectory.AzimuthMagnetic);
|
||||
row.Cell(5).SetCellValue(trajectory.VerticalDepth);
|
||||
row.Cell(6).SetCellValue(trajectory.Comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,13 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Export
|
||||
|
||||
protected override void AddCoordinatesToRow(IXLRow row, TrajectoryGeoPlanDto trajectory)
|
||||
{
|
||||
row.Cell(1).Value = trajectory.WellboreDepth;
|
||||
row.Cell(2).Value = trajectory.ZenithAngle;
|
||||
row.Cell(3).Value = trajectory.AzimuthGeo;
|
||||
row.Cell(4).Value = trajectory.AzimuthMagnetic;
|
||||
row.Cell(5).Value = trajectory.VerticalDepth;
|
||||
row.Cell(6).Value = trajectory.Radius;
|
||||
row.Cell(7).Value = trajectory.Comment;
|
||||
row.Cell(1).SetCellValue(trajectory.WellboreDepth);
|
||||
row.Cell(2).SetCellValue(trajectory.ZenithAngle);
|
||||
row.Cell(3).SetCellValue(trajectory.AzimuthGeo);
|
||||
row.Cell(4).SetCellValue(trajectory.AzimuthMagnetic);
|
||||
row.Cell(5).SetCellValue(trajectory.VerticalDepth);
|
||||
row.Cell(6).SetCellValue(trajectory.Radius);
|
||||
row.Cell(7).SetCellValue(trajectory.Comment);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,11 +32,9 @@ public abstract class TrajectoryParserService<T> : ParserServiceBase<T, IParserO
|
||||
|
||||
public override ParserResultDto<T> Parse(Stream file, IParserOptionsRequest options)
|
||||
{
|
||||
using var workbook = new XLWorkbook(file, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(file);
|
||||
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws =>
|
||||
ws.Name.ToLower().Trim() == SheetName.ToLower().Trim())
|
||||
?? throw new FileFormatException($"Книга excel не содержит листа {SheetName}.");
|
||||
var sheet = workbook.GetWorksheet(SheetName);
|
||||
|
||||
var trajectoryRows = ParseExcelSheet(sheet, ParseRow, ColumnCount, HeaderRowsCount);
|
||||
return trajectoryRows;
|
||||
|
@ -15,7 +15,7 @@ public class WellOperationDefaultExcelParser : IWellOperationExcelParser<WellOpe
|
||||
{
|
||||
public SheetDto Parse(Stream stream, WellOperationImportDefaultOptionsDto options)
|
||||
{
|
||||
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(stream);
|
||||
|
||||
return ParseWorkbook(workbook, options);
|
||||
}
|
||||
@ -26,9 +26,7 @@ public class WellOperationDefaultExcelParser : IWellOperationExcelParser<WellOpe
|
||||
? DefaultTemplateInfo.SheetNamePlan
|
||||
: DefaultTemplateInfo.SheetNameFact;
|
||||
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws =>
|
||||
string.Equals(ws.Name, sheetName, StringComparison.CurrentCultureIgnoreCase))
|
||||
?? throw new FileFormatException($"Книга excel не содержит листа '{sheetName}'");
|
||||
var sheet = workbook.GetWorksheet(sheetName);
|
||||
|
||||
return ParseSheet(sheet);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class WellOperationGazpromKhantosExcelParser : IWellOperationExcelParser<
|
||||
|
||||
public SheetDto Parse(Stream stream, WellOperationImportGazpromKhantosOptionsDto options)
|
||||
{
|
||||
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(stream);
|
||||
|
||||
return ParseWorkBook(workbook, options);
|
||||
}
|
||||
@ -54,10 +54,7 @@ public class WellOperationGazpromKhantosExcelParser : IWellOperationExcelParser<
|
||||
if (options.EndRow < options.StartRow)
|
||||
throw new ArgumentInvalidException(nameof(options.EndRow), "Конечный номер строки не может быть больше начального");
|
||||
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws =>
|
||||
string.Equals(ws.Name, options.SheetName, StringComparison.CurrentCultureIgnoreCase))
|
||||
?? throw new FileFormatException($"Книга excel не содержит листа '{options.SheetName}'");
|
||||
|
||||
var sheet = workbook.GetWorksheet(options.SheetName);
|
||||
return ParseSheet(sheet, options.StartRow, options.EndRow);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationImport;
|
||||
|
||||
public class WellOperationExportService : IWellOperationExportService
|
||||
{
|
||||
//TODO: удалить неиспользуемую зависимость
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
private readonly IWellService wellService;
|
||||
private readonly IWellOperationImportTemplateService wellOperationImportTemplateService;
|
||||
@ -42,7 +43,7 @@ public class WellOperationExportService : IWellOperationExportService
|
||||
{
|
||||
using Stream ecxelTemplateStream = wellOperationImportTemplateService.GetExcelTemplateStream();
|
||||
|
||||
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(ecxelTemplateStream);
|
||||
AddOperationsToWorkbook(workbook, operations);
|
||||
|
||||
var memoryStream = new MemoryStream();
|
||||
@ -56,17 +57,17 @@ public class WellOperationExportService : IWellOperationExportService
|
||||
var planOperations = operations.Where(o => o.IdType == 0);
|
||||
if (planOperations.Any())
|
||||
{
|
||||
var sheetPlan = workbook.Worksheets.FirstOrDefault(ws => ws.Name == DefaultTemplateInfo.SheetNamePlan);
|
||||
if (sheetPlan is not null)
|
||||
AddOperationsToSheet(sheetPlan, planOperations);
|
||||
var sheetPlan = workbook.GetWorksheet(DefaultTemplateInfo.SheetNamePlan);
|
||||
|
||||
AddOperationsToSheet(sheetPlan, planOperations);
|
||||
}
|
||||
|
||||
var factOperations = operations.Where(o => o.IdType == 1);
|
||||
if (factOperations.Any())
|
||||
{
|
||||
var sheetFact = workbook.Worksheets.FirstOrDefault(ws => ws.Name == DefaultTemplateInfo.SheetNameFact);
|
||||
if (sheetFact is not null)
|
||||
AddOperationsToSheet(sheetFact, factOperations);
|
||||
var sheetFact = workbook.GetWorksheet(DefaultTemplateInfo.SheetNameFact);
|
||||
|
||||
AddOperationsToSheet(sheetFact, factOperations);
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,13 +88,16 @@ public class WellOperationExportService : IWellOperationExportService
|
||||
private static void AddOperationToRow(IXLRow row, WellOperationDto operation, IEnumerable<WellSectionTypeDto> sections,
|
||||
IEnumerable<WellOperationCategoryDto> categories)
|
||||
{
|
||||
row.Cell(DefaultTemplateInfo.ColumnSection).Value = sections.First(s => s.Id == operation.IdWellSectionType).Caption;
|
||||
row.Cell(DefaultTemplateInfo.ColumnCategory).Value = categories.First(o => o.Id == operation.IdCategory).Name;
|
||||
row.Cell(DefaultTemplateInfo.ColumnCategoryInfo).Value = operation.CategoryInfo;
|
||||
row.Cell(DefaultTemplateInfo.ColumnDepthStart).Value = operation.DepthStart;
|
||||
row.Cell(DefaultTemplateInfo.ColumnDepthEnd).Value = operation.DepthEnd;
|
||||
row.Cell(DefaultTemplateInfo.ColumnDate).Value = operation.DateStart;
|
||||
row.Cell(DefaultTemplateInfo.ColumnDuration).Value = operation.DurationHours;
|
||||
row.Cell(DefaultTemplateInfo.ColumnComment).Value = operation.Comment;
|
||||
var sectionCaption = sections.First(s => s.Id == operation.IdWellSectionType).Caption;
|
||||
var categoryName = categories.First(o => o.Id == operation.IdCategory).Name;
|
||||
|
||||
row.Cell(DefaultTemplateInfo.ColumnSection).SetCellValue(sectionCaption);
|
||||
row.Cell(DefaultTemplateInfo.ColumnCategory).SetCellValue(categoryName);
|
||||
row.Cell(DefaultTemplateInfo.ColumnCategoryInfo).SetCellValue(operation.CategoryInfo);
|
||||
row.Cell(DefaultTemplateInfo.ColumnDepthStart).SetCellValue(operation.DepthStart);
|
||||
row.Cell(DefaultTemplateInfo.ColumnDepthEnd).SetCellValue(operation.DepthEnd);
|
||||
row.Cell(DefaultTemplateInfo.ColumnDate).SetCellValue(operation.DateStart);
|
||||
row.Cell(DefaultTemplateInfo.ColumnDuration).SetCellValue(operation.DurationHours);
|
||||
row.Cell(DefaultTemplateInfo.ColumnComment).SetCellValue(operation.Comment);
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
?? throw new ArgumentInvalidException(nameof(idWell), "idWell doesn`t exist");
|
||||
|
||||
var ecxelTemplateStream = GetExcelTemplateStream();
|
||||
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
|
||||
using var workbook = new XLWorkbook(ecxelTemplateStream);
|
||||
FillScheduleSheetToWorkbook(workbook, tvd, well);
|
||||
FillTvdSheetToWorkbook(workbook, tvd, well);
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
@ -72,9 +72,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
|
||||
private static void FillCurrentScheduleSheet(XLWorkbook workbook, IEnumerable<WellOperationDto> tvdList, string sheetName)
|
||||
{
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName);
|
||||
if (sheet is null)
|
||||
return;
|
||||
var sheet = workbook.GetWorksheet(sheetName);
|
||||
|
||||
const int headerRowsCount = 6;
|
||||
|
||||
@ -103,9 +101,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
|
||||
private static void FillScheduleSheet(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
|
||||
{
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameSchedule);
|
||||
if (sheet is null)
|
||||
return;
|
||||
var sheet = workbook.GetWorksheet(sheetNameSchedule);
|
||||
|
||||
const int headerRowsCount = 6;
|
||||
const int rowTitle = 3;
|
||||
@ -132,7 +128,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
const int columnNpt = 21;
|
||||
|
||||
var subTitle = $"на строительство скважины №{well.Caption}, куст: {well.Cluster}, м/р: {well.Deposit}";
|
||||
sheet.Row(rowTitle).Cell(3).Value = subTitle;
|
||||
sheet.Row(rowTitle).Cell(3).SetCellValue(subTitle);
|
||||
|
||||
var tvdList = tvd.ToList();
|
||||
var facts = tvd
|
||||
@ -228,7 +224,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
|
||||
var rowSummary = sheet.Row(rowNumSummary);
|
||||
rowSummary.Style.Font.Bold = true;
|
||||
rowSummary.Cell(columnCaption).Value = "Итого:";
|
||||
rowSummary.Cell(columnCaption).SetCellValue("Итого:");
|
||||
|
||||
AddRangeFormula(rowSummary, "sum", columnDeltaWellDepthPerDay);
|
||||
AddRangeFormula(rowSummary, "sum", columnDurationPlan);
|
||||
@ -241,9 +237,8 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
SetBorder(rowSummary.Cells(true).Style);
|
||||
|
||||
var rowSummary2 = sheet.Row(rowNumSummary + 1);
|
||||
rowSummary2.DataType = XLDataType.Number;
|
||||
rowSummary2.Style.NumberFormat.Format = "0,00";
|
||||
rowSummary2.Cell(columnCaption).Value = "в сутках:";
|
||||
rowSummary2.Cell(columnCaption).SetCellValue("в сутках:");
|
||||
rowSummary2.Cell(columnDurationPlan).FormulaA1 = $"={GetColunmLetter(columnDurationPlan)}{rowNumSummary}/24";
|
||||
SetNumber(rowSummary2.Cell(columnDurationPlan));
|
||||
rowSummary2.Cell(columnDurationFact).FormulaA1 = $"={GetColunmLetter(columnDurationFact)}{rowNumSummary}/24";
|
||||
@ -255,9 +250,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
|
||||
private static void FillTvdSheetToWorkbook(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
|
||||
{
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameTvd);
|
||||
if (sheet is null)
|
||||
return;
|
||||
var sheet = workbook.GetWorksheet(sheetNameTvd);
|
||||
|
||||
const int rowTitle = 2;
|
||||
const int rowSubtitle = 3;
|
||||
@ -346,14 +339,12 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
|
||||
private static IXLCell SetDateTime(IXLCell cell)
|
||||
{
|
||||
cell.DataType = XLDataType.DateTime;
|
||||
cell.Style.DateFormat.Format = "DD.MM.YYYY HH:MM:SS";
|
||||
return cell;
|
||||
}
|
||||
|
||||
private static IXLCell SetNumber(IXLCell cell)
|
||||
{
|
||||
cell.DataType = XLDataType.Number;
|
||||
cell.Style.NumberFormat.Format = "0.00";
|
||||
return cell;
|
||||
}
|
||||
@ -361,7 +352,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
private static IXLCell SetCell(IXLRow row, int colunm, object? value)
|
||||
{
|
||||
var cell = row.Cell(colunm);
|
||||
cell.Value = value;
|
||||
cell.SetCellValue(value);
|
||||
|
||||
SetBorder(cell.Style);
|
||||
cell.Style.Alignment.WrapText = true;
|
||||
|
Loading…
Reference in New Issue
Block a user