[後端] 修改獨立棟別以sheet區分
This commit is contained in:
parent
008e10c439
commit
518a97e461
@ -418,8 +418,6 @@ namespace FrontendWebApi.ApiControllers
|
||||
}
|
||||
List<Dictionary<string, byte[]>> docFile = new List<Dictionary<string, byte[]>>();
|
||||
|
||||
foreach (var r in result)
|
||||
{
|
||||
var workbook = new XSSFWorkbook();
|
||||
#region excel設定
|
||||
IFont font12 = workbook.CreateFont();
|
||||
@ -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();
|
||||
}
|
||||
|
||||
var ms = new NpoiMemoryStream
|
||||
{
|
||||
AllowClose = false
|
||||
};
|
||||
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))
|
||||
{
|
||||
foreach(var d in docFile)
|
||||
{
|
||||
foreach(var dic in d)
|
||||
{
|
||||
zip.AddEntry(dic.Key, dic.Value);
|
||||
}
|
||||
}
|
||||
zip.Save(zipMs);
|
||||
}
|
||||
|
||||
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,12 +602,6 @@ namespace FrontendWebApi.ApiControllers
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
@ -659,6 +644,12 @@ namespace FrontendWebApi.ApiControllers
|
||||
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 sheet = workbook.CreateSheet($"{b.full_name}電表報表");
|
||||
int RowPosition = 0;
|
||||
@ -793,27 +784,18 @@ namespace FrontendWebApi.ApiControllers
|
||||
cell.CellStyle = style12;
|
||||
}
|
||||
}
|
||||
MemoryStream ms = new MemoryStream();
|
||||
}
|
||||
}
|
||||
|
||||
var ms = new NpoiMemoryStream
|
||||
{
|
||||
AllowClose = false
|
||||
};
|
||||
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))
|
||||
{
|
||||
foreach (var d in docFile)
|
||||
{
|
||||
foreach (var dic in d)
|
||||
{
|
||||
zip.AddEntry(dic.Key, dic.Value);
|
||||
}
|
||||
}
|
||||
zip.Save(zipMs);
|
||||
}
|
||||
|
||||
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