DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/WellOperationImportService.cs
Фролов 4fe570f3e9 Refactor WellOperation WellDepth split to DepthStart and DepthEnd.
Fix other services to use new model.
2021-10-08 11:30:06 +05:00

38 lines
1.4 KiB
C#

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClosedXML.Excel;
using AsbCloudApp.Data;
namespace AsbCloudInfrastructure.Services
{
public class WellOperationImportService
{
private const string sheetNamePlan = "План";
private const string sheetNameFact = "Факт";
public IEnumerable<WellOperationDto> ParseFile(string excelFilePath)
{
if (!File.Exists(excelFilePath))
throw new FileNotFoundException($"Файл {excelFilePath} не найден.");
using var sourceExcelWorkbook = new XLWorkbook(excelFilePath, XLEventTracking.Disabled);
var sheetPlan = sourceExcelWorkbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlan);
if (sheetPlan is null)
throw new FileFormatException($"Файл {excelFilePath} не не содержит листа {sheetNamePlan}.");
var sheetFact = sourceExcelWorkbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameFact);
if (sheetFact is null)
throw new FileFormatException($"Файл {excelFilePath} не не содержит листа {sheetNameFact}.");
var wellOperations = new List<WellOperationDto>();
return wellOperations;
}
}
}