260320_01_ENH: Data Export에 날짜 범위 조회 추가, Data Export시 두번째 시트에 변수가이드 나오게 수정
This commit is contained in:
@@ -128,12 +128,33 @@ namespace REPORT_API_ver6.Controllers
|
|||||||
Project project = new Project();
|
Project project = new Project();
|
||||||
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
||||||
|
|
||||||
DataTable headerTable = project.getExportHeader(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.IsAdmin);
|
string fileName = "[DATA]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
||||||
DataTable bodyTable = project.getProjectData(pkeyInfo.Pkey, "", "", "", "", pkeyInfo.isKiwi, 1,"", "", type);
|
byte[] fileByteArray = project.makeDataAndGuidFile(pkeyInfo, userInfo, type, "ALL");
|
||||||
DataTable exportTable = project.makeExportTable(headerTable, bodyTable);
|
|
||||||
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||||
|
return File(fileByteArray, "application/octet-stream", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||||
|
return Content(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("data/{start}/{end}")]
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult ExportDataWithDate(
|
||||||
|
[FromHeader] string token, [FromHeader] string skey, [FromHeader] string type
|
||||||
|
,[FromRoute] string start, [FromRoute] string end
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UserInfo userInfo = Security.ValidateToken(token);
|
||||||
|
|
||||||
|
if (userInfo != null)
|
||||||
|
{
|
||||||
|
Project project = new Project();
|
||||||
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
||||||
|
|
||||||
string fileName = "[DATA]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
string fileName = "[DATA]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
||||||
byte[] fileByteArray = Common.DataTableToExcel(exportTable);
|
byte[] fileByteArray = project.makeDataAndGuidFile(pkeyInfo, userInfo, type, "ALL", start, end);
|
||||||
|
|
||||||
Response.StatusCode = (int)HttpStatusCode.OK;
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||||
return File(fileByteArray, "application/octet-stream", fileName);
|
return File(fileByteArray, "application/octet-stream", fileName);
|
||||||
@@ -152,10 +173,9 @@ namespace REPORT_API_ver6.Controllers
|
|||||||
{
|
{
|
||||||
Project project = new Project();
|
Project project = new Project();
|
||||||
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
||||||
DataTable guideTable = project.makeGuideTable(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.IsAdmin);
|
|
||||||
|
|
||||||
string fileName = "[GUIDE]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
string fileName = "[GUIDE]" + pkeyInfo.Pkey + "_" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".xlsx";
|
||||||
byte[] fileByteArray = Common.DataTableToExcel(guideTable);
|
byte[] fileByteArray = project.makeDataAndGuidFile(pkeyInfo, userInfo, "", "GUIDE");
|
||||||
|
|
||||||
Response.StatusCode = (int)HttpStatusCode.OK;
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
||||||
return File(fileByteArray, "application/octet-stream", fileName);
|
return File(fileByteArray, "application/octet-stream", fileName);
|
||||||
|
|||||||
15
REPORT_API_ver6/Models/CommonModels.cs
Normal file
15
REPORT_API_ver6/Models/CommonModels.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace REPORT_API_ver6.Models;
|
||||||
|
|
||||||
|
public class DataTabelToExcelSheet
|
||||||
|
{
|
||||||
|
public DataTable ExcelData { get; set; } = new DataTable();
|
||||||
|
public string SheetName { get; set; } = string.Empty;
|
||||||
|
public DataTabelToExcelSheet(DataTable excelData, string sheetName)
|
||||||
|
{
|
||||||
|
ExcelData = excelData;
|
||||||
|
SheetName = sheetName;
|
||||||
|
}
|
||||||
|
public DataTabelToExcelSheet() { }
|
||||||
|
}
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Controllers\" />
|
<Folder Include="Controllers\" />
|
||||||
<Folder Include="file_forms\" />
|
<Folder Include="file_forms\" />
|
||||||
<Folder Include="Models\" />
|
|
||||||
<Folder Include="upload_data\" />
|
<Folder Include="upload_data\" />
|
||||||
<Folder Include="Services\" />
|
<Folder Include="Services\" />
|
||||||
<Folder Include="nlp_model\" />
|
<Folder Include="nlp_model\" />
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using System.Net;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using REPORT_API_ver6.Models;
|
||||||
|
|
||||||
namespace REPORT_API_ver6.Services
|
namespace REPORT_API_ver6.Services
|
||||||
{
|
{
|
||||||
@@ -494,6 +495,35 @@ namespace REPORT_API_ver6.Services
|
|||||||
return excelPackage.GetAsByteArray();
|
return excelPackage.GetAsByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// DataTable을 Excel로 변환
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="excelTable">변환할 DataTable</param>
|
||||||
|
/// <param name="sheetName">만들 Sheet Name / 기본값 : Sheet1</param>
|
||||||
|
/// <returns>Excel파일</returns>
|
||||||
|
public static byte[] DataTableToExcel(List<DataTabelToExcelSheet> excelDataList)
|
||||||
|
{
|
||||||
|
ExcelPackage excelPackage = new ExcelPackage();
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
foreach(DataTabelToExcelSheet excelData in excelDataList)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(excelData.SheetName))
|
||||||
|
{
|
||||||
|
excelData.SheetName = "Sheet" + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add(excelData.SheetName);
|
||||||
|
worksheet.Cells["A1"].LoadFromDataTable(excelData.ExcelData, true);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return excelPackage.GetAsByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DataTable을 CSV로 변환
|
/// DataTable을 CSV로 변환
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1918,14 +1918,36 @@ namespace REPORT_API_ver6.Services
|
|||||||
returnTable.Rows.Add(labelRow);
|
returnTable.Rows.Add(labelRow);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return returnTable;
|
return returnTable;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] makeDataAndGuidFile(PkeyInfo pkeyInfo, UserInfo userInfo, string dataType, string fileTarget, string start = "", string end = "")
|
||||||
|
{
|
||||||
|
List<DataTabelToExcelSheet> excelDataList = new List<DataTabelToExcelSheet>();
|
||||||
|
|
||||||
|
if (fileTarget.ToUpper() == "ALL" || fileTarget.ToUpper() == "DATA")
|
||||||
|
{
|
||||||
|
DataTable headerTable = getExportHeader(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.IsAdmin);
|
||||||
|
DataTable bodyTable = getProjectData(pkeyInfo.Pkey, "", "", start, end, pkeyInfo.isKiwi, 1,"", "", dataType);
|
||||||
|
DataTable dataTable = makeExportTable(headerTable, bodyTable);
|
||||||
|
|
||||||
|
excelDataList.Add(new DataTabelToExcelSheet(dataTable, "DATA"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileTarget.ToUpper() == "ALL" || fileTarget.ToUpper() == "GUIDE")
|
||||||
|
{
|
||||||
|
DataTable guideTable = makeGuideTable(pkeyInfo.Pkey, pkeyInfo.isKiwi, userInfo.IsAdmin);
|
||||||
|
|
||||||
|
excelDataList.Add(new DataTabelToExcelSheet(guideTable, "GUIDE"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Common.DataTableToExcel(excelDataList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 저장된 북마크 정보 반환
|
/// 저장된 북마크 정보 반환
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user