[FE API] 未完成 可成功匯出資料 但總計還沒加

This commit is contained in:
keke 2023-08-29 18:04:48 +08:00
parent 613d53651f
commit 02db092954

View File

@ -829,9 +829,9 @@ namespace FrontendWebApi.ApiControllers
[Route("api/ExportElectricEachTotalCompareList")] [Route("api/ExportElectricEachTotalCompareList")]
public FileResult OpeExportEachTotalCompareExcelElec([FromBody] HydroMeterInput input) public FileResult OpeExportEachTotalCompareExcelElec([FromBody] HydroMeterInput input)
{ {
List<List<HydroMeterOutput>> result = new List<List<HydroMeterOutput>>(); List<HydroMeterOutput> result = new List<HydroMeterOutput>();
result.Add(ElectricListEachTotal(input).Result.Value.Data.ToList()); result = ElectricListEachTotal(input).Result.Value.Data.ToList();
List<Dictionary<string, byte[]>> docFile = new List<Dictionary<string, byte[]>>(); List<Dictionary<string, byte[]>> docFile = new List<Dictionary<string, byte[]>>();
@ -880,8 +880,8 @@ namespace FrontendWebApi.ApiControllers
using (FileStream templateStream = new FileStream(".\\template\\ElectricEachTotalCompare_temp.xlsx", FileMode.Open, FileAccess.Read)) using (FileStream templateStream = new FileStream(".\\template\\ElectricEachTotalCompare_temp.xlsx", FileMode.Open, FileAccess.Read))
{ {
var templateWorkbook = new XSSFWorkbook(templateStream); workbook = new XSSFWorkbook(templateStream);
var sheet = templateWorkbook.GetSheetAt(0); // 這裡假設您要使用第一個工作表 var sheet = workbook.GetSheetAt(0); // 這裡假設您要使用第一個工作表
// 設定要填入資料的位置rowIndex 和 columnIndex // 設定要填入資料的位置rowIndex 和 columnIndex
int rowIndex = 4; // 假設要從第二列開始填入 int rowIndex = 4; // 假設要從第二列開始填入
@ -892,16 +892,16 @@ namespace FrontendWebApi.ApiControllers
columnIndex = 1; columnIndex = 1;
IRow row = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex); IRow row = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex);
string buildingName = r.Select(x => x.building_name).FirstOrDefault(); string buildingName = r.building_name;
string floorTag = r.Select(x => x.floor_tag).FirstOrDefault(); string floorTag = r.floor_tag;
ICell cell = row.GetCell(columnIndex) ?? row.CreateCell(columnIndex); ICell cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
cell.SetCellValue(buildingName + floorTag); cell.SetCellValue(buildingName + floorTag);
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++); cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
string deviceFullName = r.Select(x => x.device_full_name).FirstOrDefault(); string deviceFullName = r.device_full_name;
cell.SetCellValue(deviceFullName); cell.SetCellValue(deviceFullName);
foreach (var rawD in r.FirstOrDefault().rawData) foreach (var rawD in r.rawData)
{ {
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++); cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
cell.SetCellValue(rawD.avg_rawdata); cell.SetCellValue(rawD.avg_rawdata);
@ -939,7 +939,7 @@ namespace FrontendWebApi.ApiControllers
ms.Flush(); ms.Flush();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
return File(ms, "application/vnd.ms", @$"電表報表{System.DateTime.Now.ToString("yyyyMMddHHmm")}.xlsx"); return File(ms, "application/vnd.ms", @$"用電差異比較表{System.DateTime.Now.ToString("yyyyMMddHHmm")}.xlsx");
} }
[HttpPost] [HttpPost]