[後端] 修改獨立棟別以sheet區分
This commit is contained in:
parent
008e10c439
commit
518a97e461
@ -418,10 +418,8 @@ namespace FrontendWebApi.ApiControllers
|
||||
}
|
||||
List<Dictionary<string, byte[]>> docFile = new List<Dictionary<string, byte[]>>();
|
||||
|
||||
foreach (var r in result)
|
||||
{
|
||||
var workbook = new XSSFWorkbook();
|
||||
#region excel設定
|
||||
var workbook = new XSSFWorkbook();
|
||||
#region excel設定
|
||||
IFont font12 = workbook.CreateFont();
|
||||
font12.FontName = "新細明體";
|
||||
font12.FontHeightInPoints = 12;
|
||||
@ -462,6 +460,8 @@ namespace FrontendWebApi.ApiControllers
|
||||
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
stylein12.WrapText = true;
|
||||
#endregion
|
||||
foreach (var r in result)
|
||||
{
|
||||
string buildingName = r.Select(x => x.building_name).FirstOrDefault();
|
||||
var sheet = workbook.CreateSheet($"{buildingName}電表報表");
|
||||
int RowPosition = 0;
|
||||
@ -551,26 +551,17 @@ namespace FrontendWebApi.ApiControllers
|
||||
}
|
||||
}
|
||||
}
|
||||
MemoryStream ms = new MemoryStream();
|
||||
workbook.Write(ms);
|
||||
docFile.Add(new Dictionary<string, byte[]>() { { $"{buildingName}電表報表.xlsx", ms.ToArray() } });
|
||||
}
|
||||
|
||||
var zipMs = new MemoryStream();
|
||||
using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(System.Text.Encoding.UTF8))
|
||||
var ms = new NpoiMemoryStream
|
||||
{
|
||||
foreach(var d in docFile)
|
||||
{
|
||||
foreach(var dic in d)
|
||||
{
|
||||
zip.AddEntry(dic.Key, dic.Value);
|
||||
}
|
||||
}
|
||||
zip.Save(zipMs);
|
||||
}
|
||||
|
||||
AllowClose = false
|
||||
};
|
||||
workbook.Write(ms);
|
||||
ms.Flush();
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
return File(zipMs.ToArray(), "application/octet-stream", "電表報表.zip");
|
||||
return File(ms, "application/vnd.ms", "電表報表.xlsx");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -611,54 +602,54 @@ namespace FrontendWebApi.ApiControllers
|
||||
}
|
||||
}
|
||||
|
||||
var workbook = new XSSFWorkbook();
|
||||
#region excel設定
|
||||
IFont font12 = workbook.CreateFont();
|
||||
font12.FontName = "新細明體";
|
||||
font12.FontHeightInPoints = 12;
|
||||
ICellStyle style12 = workbook.CreateCellStyle();
|
||||
style12.SetFont(font12);
|
||||
style12.Alignment = HorizontalAlignment.Center;
|
||||
style12.VerticalAlignment = VerticalAlignment.Center;
|
||||
IFont font12Times = workbook.CreateFont();
|
||||
font12Times.FontName = "Times New Roman";
|
||||
font12Times.FontHeightInPoints = 12;
|
||||
IFont font18 = workbook.CreateFont();
|
||||
font18.FontName = "新細明體";
|
||||
font18.FontHeightInPoints = 18;
|
||||
font18.IsBold = true;
|
||||
ICellStyle styleTitle18 = workbook.CreateCellStyle();
|
||||
styleTitle18.SetFont(font18);
|
||||
styleTitle18.Alignment = HorizontalAlignment.Center;
|
||||
styleTitle18.VerticalAlignment = VerticalAlignment.Center;
|
||||
ICellStyle styleLeft12 = workbook.CreateCellStyle();
|
||||
styleLeft12.SetFont(font12);
|
||||
styleLeft12.Alignment = HorizontalAlignment.Left;
|
||||
styleLeft12.VerticalAlignment = VerticalAlignment.Center;
|
||||
ICellStyle styleLine12 = workbook.CreateCellStyle();
|
||||
styleLine12.SetFont(font12);
|
||||
styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
||||
styleLine12.VerticalAlignment = VerticalAlignment.Center;
|
||||
styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
ICellStyle stylein12 = workbook.CreateCellStyle();
|
||||
stylein12.SetFont(font12Times);
|
||||
stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
|
||||
stylein12.VerticalAlignment = VerticalAlignment.Center;
|
||||
stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
stylein12.WrapText = true;
|
||||
#endregion
|
||||
foreach (var b in building)
|
||||
{
|
||||
var res1 = result1.Where(x => x.Select(x => x.building_tag).Contains(b.building_tag)).ToList();
|
||||
var res2 = result2.Where(x => x.Select(x => x.building_tag).Contains(b.building_tag)).ToList();
|
||||
if (res1.Count > 0 || res2.Count > 0)
|
||||
{
|
||||
var workbook = new XSSFWorkbook();
|
||||
#region excel設定
|
||||
IFont font12 = workbook.CreateFont();
|
||||
font12.FontName = "新細明體";
|
||||
font12.FontHeightInPoints = 12;
|
||||
ICellStyle style12 = workbook.CreateCellStyle();
|
||||
style12.SetFont(font12);
|
||||
style12.Alignment = HorizontalAlignment.Center;
|
||||
style12.VerticalAlignment = VerticalAlignment.Center;
|
||||
IFont font12Times = workbook.CreateFont();
|
||||
font12Times.FontName = "Times New Roman";
|
||||
font12Times.FontHeightInPoints = 12;
|
||||
IFont font18 = workbook.CreateFont();
|
||||
font18.FontName = "新細明體";
|
||||
font18.FontHeightInPoints = 18;
|
||||
font18.IsBold = true;
|
||||
ICellStyle styleTitle18 = workbook.CreateCellStyle();
|
||||
styleTitle18.SetFont(font18);
|
||||
styleTitle18.Alignment = HorizontalAlignment.Center;
|
||||
styleTitle18.VerticalAlignment = VerticalAlignment.Center;
|
||||
ICellStyle styleLeft12 = workbook.CreateCellStyle();
|
||||
styleLeft12.SetFont(font12);
|
||||
styleLeft12.Alignment = HorizontalAlignment.Left;
|
||||
styleLeft12.VerticalAlignment = VerticalAlignment.Center;
|
||||
ICellStyle styleLine12 = workbook.CreateCellStyle();
|
||||
styleLine12.SetFont(font12);
|
||||
styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
||||
styleLine12.VerticalAlignment = VerticalAlignment.Center;
|
||||
styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
ICellStyle stylein12 = workbook.CreateCellStyle();
|
||||
stylein12.SetFont(font12Times);
|
||||
stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
|
||||
stylein12.VerticalAlignment = VerticalAlignment.Center;
|
||||
stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
stylein12.WrapText = true;
|
||||
#endregion
|
||||
|
||||
var sheet = workbook.CreateSheet($"{b.full_name}電表報表");
|
||||
int RowPosition = 0;
|
||||
@ -793,27 +784,18 @@ namespace FrontendWebApi.ApiControllers
|
||||
cell.CellStyle = style12;
|
||||
}
|
||||
}
|
||||
MemoryStream ms = new MemoryStream();
|
||||
workbook.Write(ms);
|
||||
docFile.Add(new Dictionary<string, byte[]>() { { $"{b.full_name}電表報表.xlsx", ms.ToArray() } });
|
||||
}
|
||||
}
|
||||
|
||||
var zipMs = new MemoryStream();
|
||||
using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(System.Text.Encoding.UTF8))
|
||||
var ms = new NpoiMemoryStream
|
||||
{
|
||||
foreach (var d in docFile)
|
||||
{
|
||||
foreach (var dic in d)
|
||||
{
|
||||
zip.AddEntry(dic.Key, dic.Value);
|
||||
}
|
||||
}
|
||||
zip.Save(zipMs);
|
||||
}
|
||||
|
||||
AllowClose = false
|
||||
};
|
||||
workbook.Write(ms);
|
||||
ms.Flush();
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
return File(zipMs.ToArray(), "application/octet-stream", "電表報表.zip");
|
||||
return File(ms, "application/vnd.ms-excel", "電表報表.xlsx");
|
||||
}
|
||||
|
||||
public static int GetDayInMonth(string yearMonth)
|
||||
|
Loading…
Reference in New Issue
Block a user