前端API:History 匯出 Excel 各分頁資料
This commit is contained in:
parent
b2a9df8922
commit
7cc15613bb
@ -216,32 +216,66 @@ namespace FrontendWebApi.ApiControllers
|
||||
stylein12.WrapText = true;
|
||||
#endregion
|
||||
var data = he.ToList();
|
||||
ISheet sheet = workbook.CreateSheet($"{building.Where(x => x.building_tag == lhe.device_number.Split("_")[1]).Select(x => x.full_name).FirstOrDefault()}歷史資料");
|
||||
int RowPosition = 0;
|
||||
#region set cell
|
||||
IRow row = sheet.CreateRow(RowPosition);
|
||||
sheet.SetColumnWidth(0, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(1, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(2, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(3, 4 * 160 * 12);
|
||||
ICell cell = row.CreateCell(0);
|
||||
cell.SetCellValue("類型");
|
||||
cell.CellStyle = styleLine12;
|
||||
cell = row.CreateCell(1);
|
||||
cell.SetCellValue("設備名稱");
|
||||
cell.CellStyle = styleLine12;
|
||||
cell = row.CreateCell(2);
|
||||
cell.SetCellValue("數值");
|
||||
cell = row.CreateCell(3);
|
||||
cell.SetCellValue("記錄時間");
|
||||
cell.CellStyle = styleLine12;
|
||||
#endregion
|
||||
|
||||
if (data.Count > 0)
|
||||
{
|
||||
string lastDeviceItem = string.Empty;
|
||||
int RowPosition = 0;
|
||||
IRow row;
|
||||
ISheet sheet;
|
||||
#region set cell
|
||||
sheet = workbook.CreateSheet($"{building.Where(x => x.building_tag == lhe.device_number.Split("_")[1]).Select(x => x.full_name).FirstOrDefault()}{"_" + data[0].type}");
|
||||
row = sheet.CreateRow(RowPosition);
|
||||
sheet.SetColumnWidth(0, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(1, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(2, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(3, 4 * 160 * 12);
|
||||
ICell cell = row.CreateCell(0);
|
||||
cell.SetCellValue("類型");
|
||||
cell.CellStyle = styleLine12;
|
||||
cell = row.CreateCell(1);
|
||||
cell.SetCellValue("設備名稱");
|
||||
cell.CellStyle = styleLine12;
|
||||
cell = row.CreateCell(2);
|
||||
cell.SetCellValue("數值");
|
||||
cell = row.CreateCell(3);
|
||||
cell.SetCellValue("記錄時間");
|
||||
cell.CellStyle = styleLine12;
|
||||
#endregion
|
||||
|
||||
foreach (var d in data)
|
||||
{
|
||||
RowPosition += 1;
|
||||
if (RowPosition == 0 && lastDeviceItem == "")
|
||||
{
|
||||
lastDeviceItem = d.type; //第一次不用建立 sheet;
|
||||
}
|
||||
if (d.type != lastDeviceItem)
|
||||
{
|
||||
lastDeviceItem = d.type;
|
||||
sheet = workbook.CreateSheet($"{building.Where(x => x.building_tag == lhe.device_number.Split("_")[1]).Select(x => x.full_name).FirstOrDefault()}{"_" + d.type}");
|
||||
#region set cell
|
||||
row = sheet.CreateRow(RowPosition);
|
||||
sheet.SetColumnWidth(0, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(1, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(2, 4 * 160 * 12);
|
||||
sheet.SetColumnWidth(3, 4 * 160 * 12);
|
||||
cell = row.CreateCell(0);
|
||||
cell.SetCellValue("類型");
|
||||
cell.CellStyle = styleLine12;
|
||||
cell = row.CreateCell(1);
|
||||
cell.SetCellValue("設備名稱");
|
||||
cell.CellStyle = styleLine12;
|
||||
cell = row.CreateCell(2);
|
||||
cell.SetCellValue("數值");
|
||||
cell = row.CreateCell(3);
|
||||
cell.SetCellValue("記錄時間");
|
||||
cell.CellStyle = styleLine12;
|
||||
#endregion
|
||||
RowPosition = 0;
|
||||
}
|
||||
else {
|
||||
RowPosition += 1;
|
||||
}
|
||||
|
||||
row = sheet.CreateRow(RowPosition);
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user