2022-06-17 13:20:48 +05:00
|
|
|
|
using AsbCloudApp.Data.DailyReportModel;
|
|
|
|
|
using AsbCloudInfrastructure.EfCache;
|
|
|
|
|
using ClosedXML.Excel;
|
2022-05-05 10:06:15 +05:00
|
|
|
|
using System;
|
2022-06-17 13:20:48 +05:00
|
|
|
|
using System.IO;
|
2022-04-22 17:17:38 +05:00
|
|
|
|
using System.Linq;
|
2022-05-31 16:38:04 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-10-26 17:22:32 +05:00
|
|
|
|
|
|
|
|
|
namespace ConsoleApp1
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
2022-06-15 14:57:37 +05:00
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
class Program
|
2021-10-03 20:08:17 +05:00
|
|
|
|
{
|
2022-06-01 12:18:10 +05:00
|
|
|
|
// use ServiceFactory to make services
|
2021-07-28 09:47:13 +05:00
|
|
|
|
static void Main(/*string[] args*/)
|
2021-11-17 10:52:03 +05:00
|
|
|
|
{
|
2022-06-17 13:20:48 +05:00
|
|
|
|
var block = new DailyReportHeadDto()
|
2022-05-06 16:35:16 +05:00
|
|
|
|
{
|
2022-06-17 13:20:48 +05:00
|
|
|
|
AzimuthAngle=12,
|
|
|
|
|
WellName= "WellName",
|
|
|
|
|
ClusterName= "clusterName",
|
|
|
|
|
Customer="customer",
|
|
|
|
|
Contractor="Contractor",
|
|
|
|
|
ReportDate = DateTime.Now,
|
|
|
|
|
WellDepthIntervalFinishDate= 27.5,
|
|
|
|
|
WellDepthIntervalStartDate= 26.5,
|
|
|
|
|
BottomholeDepth= 66.6
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var ms = MakeReportFromBlocks(block);
|
|
|
|
|
//File.Create("", MakeReportFromBlocks(block));
|
|
|
|
|
using var file = new FileStream("file.xlsx", FileMode.Create, System.IO.FileAccess.Write);
|
|
|
|
|
byte[] bytes = new byte[ms.Length];
|
|
|
|
|
ms.Read(bytes, 0, (int)ms.Length);
|
|
|
|
|
file.Write(bytes, 0, bytes.Length);
|
|
|
|
|
ms.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Stream MakeReportFromBlocks(DailyReportHeadDto blockHead)
|
|
|
|
|
{
|
|
|
|
|
using var workbook = new XLWorkbook();
|
|
|
|
|
FillSheet6blocks(workbook, blockHead);
|
|
|
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
|
|
|
workbook.SaveAs(memoryStream, new SaveOptions { });
|
|
|
|
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
return memoryStream;
|
2021-10-06 16:30:46 +05:00
|
|
|
|
}
|
2022-05-31 16:38:04 +05:00
|
|
|
|
|
2022-06-17 13:20:48 +05:00
|
|
|
|
private static String converteCellCoordinate(int row, bool isCaps, int column)
|
2022-05-31 16:38:04 +05:00
|
|
|
|
{
|
2022-06-17 13:20:48 +05:00
|
|
|
|
var c = (Char)((isCaps ? 65 : 97) + (column - 1));
|
|
|
|
|
string convertColumn = c.ToString();
|
|
|
|
|
return $"{convertColumn}{row}";
|
2022-05-31 16:38:04 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 13:20:48 +05:00
|
|
|
|
public static void FillSheet6blocks(XLWorkbook workbook, DailyReportHeadDto blockHead)
|
2022-05-31 16:38:04 +05:00
|
|
|
|
{
|
2022-06-17 13:20:48 +05:00
|
|
|
|
var sheet = workbook.Worksheets.Add(blockHead.ReportDate.ToString("dd.MM.yyyy"));
|
|
|
|
|
//sheet.Name = blockHead.ReportDate.ToString("dd.MM.yyyy");
|
|
|
|
|
|
|
|
|
|
var tuple = (row: 3, column: 3);
|
|
|
|
|
|
|
|
|
|
tuple = (AddBlockHead1(sheet, blockHead, (tuple.row, tuple.column)).row, AddBlockHead1(sheet, blockHead, (tuple.row, tuple.column)).column);
|
|
|
|
|
//sheet.Columns().AdjustToContents();
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
private static (int row, int column) AddBlockHead1(IXLWorksheet sheet, DailyReportHeadDto blockDto, (int row, int column) tupleStart)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var tuple = (row: tupleStart.row, column: tupleStart.column);
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value =
|
|
|
|
|
$"Суточная сводка бурения скважины: {blockDto.WellName}, куст: {blockDto.ClusterName}";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 7).Merge();
|
|
|
|
|
//4
|
|
|
|
|
tuple.row += 1;
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value =
|
|
|
|
|
$"Заказчик: {blockDto.Customer}";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 7).Merge();
|
|
|
|
|
tuple.row += 1;
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value =
|
|
|
|
|
$"Подрядчик: {blockDto.Contractor}";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 7).Merge();
|
|
|
|
|
tuple.row += 2;
|
|
|
|
|
//7,3
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value = "Отчетный период";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 3).Merge();
|
|
|
|
|
tuple.column += 4;
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value = "Забой за отчетный период, м";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 3).Merge();
|
|
|
|
|
tuple.column = tupleStart.column;
|
|
|
|
|
tuple.row += 1;
|
|
|
|
|
//8,3
|
|
|
|
|
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value = "От (дата, время)";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 1).Merge();
|
|
|
|
|
|
|
|
|
|
tuple.column += 2; //8,5
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value = "До (дата, время)";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 1).Merge();
|
|
|
|
|
tuple.column += 2; //8,7
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value = "От";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 1).Merge();
|
|
|
|
|
tuple.column += 2; //8,9
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value = "До";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 1).Merge();
|
|
|
|
|
tuple.column = tupleStart.column;
|
|
|
|
|
tuple.row += 1; //9,3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value = $"{blockDto.ReportDate}";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 2).Merge();
|
|
|
|
|
tuple.column += 2;
|
|
|
|
|
//согласно формуле в шаблоне - ячейка С9
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).FormulaA1 = $"={converteCellCoordinate(tuple.row, true, tuple.column-2)}-1";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 2).Merge();
|
|
|
|
|
tuple.column += 2;
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value = $"{blockDto.WellDepthIntervalStartDate}";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 2).Merge();
|
|
|
|
|
tuple.column += 2;
|
|
|
|
|
sheet.Cell(tuple.row, tuple.column).Value = $"{blockDto.WellDepthIntervalFinishDate}";
|
|
|
|
|
sheet.Range(tuple.row, tuple.column, tuple.row, tuple.column + 2).Merge();
|
|
|
|
|
tuple.column = tupleStart.column;
|
|
|
|
|
tuple.row += 2; //11,3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (tuple.Item1, tuple.Item2);
|
|
|
|
|
|
2022-05-31 16:38:04 +05:00
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
2022-06-17 13:20:48 +05:00
|
|
|
|
struct CellAddress
|
|
|
|
|
{
|
|
|
|
|
public int Col { get; set; }
|
|
|
|
|
public int Row { get; set; }
|
|
|
|
|
//public string GetExcelAddress()
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|