using ClosedXML.Excel; using System; using System.Collections.Generic; using ComponentOrientedPlatform.Abstractions; namespace ReportPlugin.ExcelBigText; public sealed class BigTextExcelReport : IReportDocumentWithContextTextsContract { public string DocumentFormat => "xlsx"; public Task CreateDocumentAsync(string filePath, string header, List paragraphs) { if (string.IsNullOrWhiteSpace(filePath)) throw new ArgumentNullException(nameof(filePath)); if (string.IsNullOrWhiteSpace(header)) throw new ArgumentNullException(nameof(header)); if (paragraphs is null) throw new ArgumentNullException(nameof(paragraphs)); if (paragraphs.Count == 0) throw new ArgumentOutOfRangeException(nameof(paragraphs)); using var wb = new XLWorkbook(); var ws = wb.AddWorksheet("Текст"); ws.Cell(1, 1).Value = header; ws.Range(1, 1, 1, 1).Merge(); ws.Cell(1, 1).Style.Font.SetBold().Font.SetFontSize(18); ws.Cell(1, 1).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center); int row = 3; foreach (var p in paragraphs) { if (p is null) throw new ArgumentNullException(nameof(paragraphs), "В списке абзацев есть null."); ws.Cell(row, 1).Value = p; ws.Cell(row, 1).Style.Alignment.WrapText = true; row++; } ws.Column(1).Width = 120; wb.SaveAs(filePath); return Task.CompletedTask; } }