forked from ddrilling/AsbCloudServer
54 lines
2.4 KiB
C#
54 lines
2.4 KiB
C#
using AsbCloudApp.Data.DailyReport;
|
|
using AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks;
|
|
using ClosedXML.Excel;
|
|
using System.IO;
|
|
namespace AsbCloudInfrastructure.Services.DailyReport
|
|
{
|
|
public class DailyReportMakerExcel
|
|
{
|
|
public Stream MakeReportFromBlocks(DailyReportDto dto)
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
FillExampleBlocks(workbook, dto);
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
workbook.SaveAs(memoryStream, new SaveOptions { });
|
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
|
return memoryStream;
|
|
}
|
|
|
|
private void FillExampleBlocks(XLWorkbook workbook, DailyReportDto dto)
|
|
{
|
|
var sheet = workbook.Worksheets.Add(dto.Head.ReportDate.ToString("dd.MM.yyyy"));
|
|
var addressStart = new CellAddress(sheet, 2, 2);
|
|
var blockHeader = new HeadBlock(addressStart, dto.Head);
|
|
addressStart = blockHeader.AddressBlockEnd + (1, 0);
|
|
addressStart.ColumnNumber = 2;
|
|
var blockBha = new BhaBlock(addressStart, dto.Bha);
|
|
addressStart = blockBha.AddressBlockEnd + (1, 0);
|
|
addressStart.ColumnNumber = 2;
|
|
var timeBalance = new TimeBalanceBlock(addressStart, dto.TimeBalance);
|
|
addressStart = timeBalance.AddressBlockEnd + (1, 0);
|
|
addressStart.ColumnNumber = 2;
|
|
var blockDimensionless = new DimensionlessBlock(addressStart, dto.NoDrilling);
|
|
addressStart = blockDimensionless.AddressBlockEnd + (1, 0);
|
|
addressStart.ColumnNumber = 2;
|
|
var blockSaub = new SaubBlock(addressStart, dto.Saub, blockHeader);
|
|
addressStart = blockSaub.AddressBlockEnd + (1, 0);
|
|
blockDimensionless.SaubBlock = blockSaub;
|
|
addressStart.ColumnNumber = 2;
|
|
var blockSign = new SignBlock(addressStart, dto.Sign);
|
|
addressStart = blockSign.AddressBlockEnd + (1, 0);
|
|
addressStart.ColumnNumber = 2;
|
|
blockHeader.Draw(sheet);
|
|
blockBha.Draw(sheet);
|
|
timeBalance.Draw(sheet);
|
|
blockDimensionless.Draw(sheet);
|
|
blockSaub.Draw(sheet);
|
|
blockSign.Draw(sheet);
|
|
//sheet.Columns().AdjustToContents(); // Adjust column width
|
|
sheet.Rows().AdjustToContents();
|
|
}
|
|
}
|
|
}
|
|
|