docx Report exp

This commit is contained in:
Илья Федотов 2024-07-10 18:32:46 +04:00
parent 642291fa0a
commit 1e4ea0c6d7
9 changed files with 60 additions and 49 deletions

View File

@ -73,7 +73,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return list;
}
public byte[] SavePaymeantToExcelFile(ReportBindingModel? model, int _clientID)
public byte[] SavePaymeantToExcelFile(int _clientID)
{
var document = _saveToExcel.CreateReport(new ExcelInfoClient
{
@ -83,14 +83,13 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return document;
}
public void SavePaymeantToWordFile(ReportBindingModel model)
public byte[] SavePaymeantToWordFile(int _clientID)
{
_saveToWord.CreateDoc(new WordInfoClient
{
//FileName = model.ProductName,
var document = _saveToWord.CreateDoc(new WordInfoClient {
Title = "Список оплат",
ListPaymeant = _paymeantstorage.GetFullList(),
}) ;
ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }),
});
return document;
}
}
}

View File

@ -7,7 +7,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcelClient
{
public byte[] CreateReport(ExcelInfoClient info) {
public byte[]? CreateReport(ExcelInfoClient info) {
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters {
@ -76,6 +76,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
protected abstract void MergeCells(ExcelMergeParameters excelParams);
// Сохранение файла
protected abstract byte[] SaveExcel(ExcelInfoClient info);
protected abstract byte[]? SaveExcel(ExcelInfoClient info);
}
}

View File

@ -10,7 +10,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWordClient
{
public void CreateDoc(WordInfoClient info)
public byte[]? CreateDoc(WordInfoClient info)
{
CreateWord(info);
@ -49,26 +49,17 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
});
}
SaveWord(info);
var document = SaveWord(info);
return document;
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
// Создание doc-файла
protected abstract void CreateWord(WordInfoClient info);
/// <summary>
/// Создание абзаца с текстом
/// </summary>
/// <param name="paragraph"></param>
/// <returns></returns>
// Создание абзаца с текстом
protected abstract void CreateParagraph(WordParagraph paragraph);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(WordInfoClient info);
// Сохранение файла
protected abstract byte[]? SaveWord(WordInfoClient info);
}
}

View File

@ -275,7 +275,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
mergeCells.Append(mergeCell);
}
protected override byte[] SaveExcel(ExcelInfoClient info)
protected override byte[]? SaveExcel(ExcelInfoClient info)
{
if (_spreadsheetDocument == null)
{

View File

@ -12,11 +12,9 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
private Body? _docBody;
/// <summary>
/// Получение типа выравнивания
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private MemoryStream _mem = new MemoryStream();
// Получение типа выравнивания
private static JustificationValues GetJustificationValues(WordJustificationType type)
{
return type switch
@ -27,10 +25,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
};
}
/// <summary>
/// Настройки страницы
/// </summary>
/// <returns></returns>
// Настройки страницы
private static SectionProperties CreateSectionProperties()
{
var properties = new SectionProperties();
@ -45,11 +40,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
return properties;
}
/// <summary>
/// Задание форматирования для абзаца
/// </summary>
/// <param name="paragraphProperties"></param>
/// <returns></returns>
// Задание форматирования для абзаца
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
{
if (paragraphProperties == null)
@ -83,7 +74,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
protected override void CreateWord(WordInfoClient info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
_wordDocument = WordprocessingDocument.Create(_mem, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());
@ -119,17 +110,19 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
_docBody.AppendChild(docParagraph);
}
protected override void SaveWord(WordInfoClient info)
protected override byte[]? SaveWord(WordInfoClient info)
{
if (_docBody == null || _wordDocument == null)
{
return;
return null;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Dispose();
return _mem.ToArray();
}
}
}

View File

@ -15,9 +15,9 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID);
// получения списка оплат
List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model);
void SavePaymeantToWordFile(ReportBindingModel model);
byte[] SavePaymeantToWordFile(int _clientID);
// Сохранение компонент с указанием отчета в .excel
byte[] SavePaymeantToExcelFile(ReportBindingModel? model, int _clientID);
byte[] SavePaymeantToExcelFile(int _clientID);
}
}

View File

@ -98,7 +98,19 @@ namespace ElectronicsShopRestAPI.Controllers {
[HttpGet]
public byte[] CreateXlsxReport (int _clientID) {
try {
var document = _reportLogic.SavePaymeantToExcelFile (null, _clientID);
var document = _reportLogic.SavePaymeantToExcelFile (_clientID);
return document;
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка создания файла");
throw;
}
}
[HttpGet]
public byte[] CreateDocxReport (int _clientID) {
try {
var document = _reportLogic.SavePaymeantToWordFile (_clientID);
return document;
}
catch (Exception ex) {

View File

@ -313,7 +313,23 @@ namespace ElectronicsShopUserApp.Controllers {
[HttpGet]
public IActionResult CreateExcelReport() {
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client.ID}");
if (fileMemStream == null) {
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
}
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Report.xlsx");
}
[HttpGet]
public IActionResult CreateWordReport() {
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client.ID}");
if (fileMemStream == null) {
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
}
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Report.docx");
}
}
}

View File

@ -25,9 +25,9 @@
</div>
<div class="row">
<div class="col-8">
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" style="background-color:#335a95;">Создать отчет в .xlsx</a>
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" style="background-color:#04713A;">Создать отчет в .docx</a>
<a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" style="background-color:#ad0d09;">Создать отчет в .pdf</a>
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" style="background-color:#335a95;">Экспорт отчета в .xlsx</a>
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" style="background-color:#04713A;">Экспорт отчета в .docx</a>
<a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" style="background-color:#ad0d09;">отправить на Email отчет в .pdf</a>
</div>
</h1>