forked from ddrilling/AsbCloudServer
модели ДТО и БД разбиты на 6 блоков изменен сервис DailyReport Тестовая таблица в консольном проекте
144 lines
5.9 KiB
C#
144 lines
5.9 KiB
C#
using AsbCloudApp.Data.DailyReportModel;
|
||
using AsbCloudInfrastructure.EfCache;
|
||
using ClosedXML.Excel;
|
||
using System;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace ConsoleApp1
|
||
{
|
||
|
||
class Program
|
||
{
|
||
// use ServiceFactory to make services
|
||
static void Main(/*string[] args*/)
|
||
{
|
||
var block = new DailyReportHeadDto()
|
||
{
|
||
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;
|
||
}
|
||
|
||
private static String converteCellCoordinate(int row, bool isCaps, int column)
|
||
{
|
||
var c = (Char)((isCaps ? 65 : 97) + (column - 1));
|
||
string convertColumn = c.ToString();
|
||
return $"{convertColumn}{row}";
|
||
}
|
||
|
||
public static void FillSheet6blocks(XLWorkbook workbook, DailyReportHeadDto blockHead)
|
||
{
|
||
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);
|
||
|
||
}
|
||
}
|
||
struct CellAddress
|
||
{
|
||
public int Col { get; set; }
|
||
public int Row { get; set; }
|
||
//public string GetExcelAddress()
|
||
//{
|
||
|
||
//}
|
||
}
|
||
}
|