Blame view

美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ReportsPrintLogExcelHelper.cs 1.86 KB
a7684ddb   李曜臣   批量导入导出,批量编辑
1
2
3
4
5
6
7
8
9
10
11
12
13
  using ClosedXML.Excel;
  using FoodLabeling.Application.Contracts.Dtos.Reports;
  
  namespace FoodLabeling.Application.Helpers;
  
  /// <summary>
  /// Reports  Print Log 全量导出 Excel(列与 Web Print Log 表头对齐)
  /// </summary>
  public static class ReportsPrintLogExcelHelper
  {
      /// <summary>导出表头(与 UI 一致)</summary>
      public static readonly string[] Headers =
      {
ef6b3255   杨鑫   修改BUG
14
          "Label ID", "Product Name", "Product Category", "Label Category", "Template", "Printed at", "Printed by", "Location", "Expiration"
a7684ddb   李曜臣   批量导入导出,批量编辑
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
      };
  
      /// <summary>
      ///  Print Log 行写入 xlsx 内存流(工作表名 <c>Print Log</c>)。
      /// </summary>
      public static MemoryStream BuildWorkbook(IReadOnlyList<ReportsPrintLogListItemDto> rows)
      {
          var ms = new MemoryStream();
          using var wb = new XLWorkbook();
          var ws = wb.AddWorksheet("Print Log");
          for (var i = 0; i < Headers.Length; i++)
          {
              ws.Cell(1, i + 1).Value = Headers[i];
              ws.Cell(1, i + 1).Style.Font.Bold = true;
          }
  
          var r = 2;
          foreach (var x in rows)
          {
              ws.Cell(r, 1).Value = x.LabelCode ?? string.Empty;
              ws.Cell(r, 2).Value = x.ProductName ?? string.Empty;
ef6b3255   杨鑫   修改BUG
36
37
38
              ws.Cell(r, 3).Value = x.ProductCategoryName ?? string.Empty;
              ws.Cell(r, 4).Value = x.LabelCategoryName ?? string.Empty;
              ws.Cell(r, 5).Value = x.TemplateText ?? string.Empty;
14afbc16   李曜臣   2026-6-22
39
              ws.Cell(r, 6).Value = ReportsDateTimeDisplayHelper.FormatPrintedAt(x.PrintedAt);
ef6b3255   杨鑫   修改BUG
40
41
42
              ws.Cell(r, 7).Value = x.PrintedByName ?? string.Empty;
              ws.Cell(r, 8).Value = x.LocationText ?? string.Empty;
              ws.Cell(r, 9).Value = x.ExpiryDateText ?? string.Empty;
a7684ddb   李曜臣   批量导入导出,批量编辑
43
44
45
46
47
48
49
50
51
              r++;
          }
  
          ws.Columns().AdjustToContents();
          wb.SaveAs(ms);
          ms.Position = 0;
          return ms;
      }
  }