前端API:History 匯出 Excel 各分頁資料
This commit is contained in:
		
							parent
							
								
									b2a9df8922
								
							
						
					
					
						commit
						7cc15613bb
					
				@ -216,10 +216,15 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
                stylein12.WrapText = true;
 | 
					                stylein12.WrapText = true;
 | 
				
			||||||
                #endregion
 | 
					                #endregion
 | 
				
			||||||
                var data = he.ToList();
 | 
					                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()}歷史資料");
 | 
					                if (data.Count > 0)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    string lastDeviceItem = string.Empty;
 | 
				
			||||||
                    int RowPosition = 0;
 | 
					                    int RowPosition = 0;
 | 
				
			||||||
 | 
					                    IRow row;
 | 
				
			||||||
 | 
					                    ISheet sheet;
 | 
				
			||||||
                    #region set cell
 | 
					                    #region set cell
 | 
				
			||||||
                IRow row = sheet.CreateRow(RowPosition);
 | 
					                    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(0, 4 * 160 * 12);
 | 
				
			||||||
                    sheet.SetColumnWidth(1, 4 * 160 * 12);
 | 
					                    sheet.SetColumnWidth(1, 4 * 160 * 12);
 | 
				
			||||||
                    sheet.SetColumnWidth(2, 4 * 160 * 12);
 | 
					                    sheet.SetColumnWidth(2, 4 * 160 * 12);
 | 
				
			||||||
@ -237,11 +242,40 @@ namespace FrontendWebApi.ApiControllers
 | 
				
			|||||||
                    cell.CellStyle = styleLine12;
 | 
					                    cell.CellStyle = styleLine12;
 | 
				
			||||||
                    #endregion
 | 
					                    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (data.Count > 0)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    foreach (var d in data)
 | 
					                    foreach (var d in data)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
 | 
					                        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;
 | 
					                            RowPosition += 1;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        
 | 
				
			||||||
                        row = sheet.CreateRow(RowPosition);
 | 
					                        row = sheet.CreateRow(RowPosition);
 | 
				
			||||||
                        for (var i = 0; i < 4; i++)
 | 
					                        for (var i = 0; i < 4; i++)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user