diff --git a/20220313_Excel/TempTask.WebEntry/ApiController/Dto/DtoInput.cs b/20220313_Excel/TempTask.WebEntry/ApiController/Dto/DtoInput.cs index b7a747e..05fb98d 100644 --- a/20220313_Excel/TempTask.WebEntry/ApiController/Dto/DtoInput.cs +++ b/20220313_Excel/TempTask.WebEntry/ApiController/Dto/DtoInput.cs @@ -28,6 +28,14 @@ namespace TempTask.WebEntry.ApiController.Dto /// public class NumZjExcel { + /// + /// 是否采用Excel的新配置方式 + /// + public bool is_excel_config { get; set; } = false; + ///// + ///// Excel新配置方式文件路径 + ///// + //public string excel_config_path { get; set; } /// /// sheet编号 从1开始 /// @@ -82,7 +90,7 @@ namespace TempTask.WebEntry.ApiController.Dto /// 跳过行 集合 行留空 /// public List skip_columns { get; set; } - + } /// /// diff --git a/20220313_Excel/TempTask.WebEntry/ApiController/NumZjController.cs b/20220313_Excel/TempTask.WebEntry/ApiController/NumZjController.cs index 36137e4..9275769 100644 --- a/20220313_Excel/TempTask.WebEntry/ApiController/NumZjController.cs +++ b/20220313_Excel/TempTask.WebEntry/ApiController/NumZjController.cs @@ -30,8 +30,7 @@ namespace TempTask.WebEntry.ApiController { var configs = App.GetConfig("NumZjConfig"); var current = configs.numZjExcels.Find(a => (int)a.excel_no == numZjDownloadInput.type); - //var sheet_names = new Dictionary { { 4, "房地产业分行业(项目信息)" }, { 5, "分地区(项目信息)" } }; - var filepath = NumZjHelper.WriteTemplate(numZjDownloadInput.year, numZjDownloadInput.month, numZjDownloadInput.week, current.excel_no, current.sheets); + var filepath = NumZjHelper.WriteTemplate(numZjDownloadInput.year, numZjDownloadInput.month, numZjDownloadInput.week, current); return new FileStreamResult(new FileStream(filepath, FileMode.Open), "application/octet-stream") { FileDownloadName = current.excel_name }; }); } diff --git a/20220313_Excel/TempTask.WebEntry/TempTask.WebEntry.csproj b/20220313_Excel/TempTask.WebEntry/TempTask.WebEntry.csproj index e9d7e46..a39f0e8 100644 --- a/20220313_Excel/TempTask.WebEntry/TempTask.WebEntry.csproj +++ b/20220313_Excel/TempTask.WebEntry/TempTask.WebEntry.csproj @@ -8,6 +8,16 @@ D:\temp_task\20220313\gitcode\number_zj\20220313_Excel\TempTask.WebEntry\TempTask.WebEntry.xml + + + + + + + PreserveNewest + + + @@ -32,4 +42,6 @@ + + diff --git a/20220313_Excel/TempTask.WebEntry/TempTask.WebEntry.xml b/20220313_Excel/TempTask.WebEntry/TempTask.WebEntry.xml index ae0706d..de2627e 100644 --- a/20220313_Excel/TempTask.WebEntry/TempTask.WebEntry.xml +++ b/20220313_Excel/TempTask.WebEntry/TempTask.WebEntry.xml @@ -24,6 +24,11 @@ + + + 是否采用Excel的新配置方式 + + sheet编号 从1开始 @@ -84,6 +89,11 @@ 跳过行 集合 行留空 + + + 跳过行 集合 行留空 + + @@ -207,11 +217,12 @@ 参数 - + + @@ -239,15 +250,19 @@ 房地产业 - + + + 城市更新0318 + + + - - + diff --git a/20220313_Excel/TempTask.WebEntry/Tools/NumZjHelper.cs b/20220313_Excel/TempTask.WebEntry/Tools/NumZjHelper.cs index fa0562d..41843bf 100644 --- a/20220313_Excel/TempTask.WebEntry/Tools/NumZjHelper.cs +++ b/20220313_Excel/TempTask.WebEntry/Tools/NumZjHelper.cs @@ -36,7 +36,12 @@ namespace TempTask.WebEntry.Tools /// 房地产业 /// [Description("住建系统抓投资情况通报(房地产业+GDP支撑性指标)样表.xlsx")] - 房地产业 = 3 + 房地产业 = 3, + /// + /// 城市更新0318 + /// + [Description("通报表格(城市更新)2022-3-18.xls")] + 城市更新0318 = 4 } /// /// @@ -44,17 +49,16 @@ namespace TempTask.WebEntry.Tools /// /// /// - /// - /// + /// /// - public static string WriteTemplate(int year, int month, int week, ExcelType excelType, List sheets) + public static string WriteTemplate(int year, int month, int week, NumZjExcel numZjExcel) { try { var _month = month.ToString().Length == 1 ? ("0" + month) : month.ToString(); var week2 = week < 10 ? ("0" + week) : week.ToString(); - int excelTypeInt = (int)excelType; - string template_name = EnumHelper.GetEnumDescription(excelType); + int excelTypeInt = (int)numZjExcel.excel_no; + string template_name = EnumHelper.GetEnumDescription(numZjExcel.excel_no); string excelFilePath = $"{App.WebHostEnvironment.WebRootPath}\\ExcelTemplate\\{template_name}"; string outputPath = string.Empty; if (!string.IsNullOrEmpty(excelFilePath)) @@ -63,7 +67,7 @@ namespace TempTask.WebEntry.Tools { bool isCompatible = ExcelHelper.GetIsCompatible(excelFilePath); IWorkbook workbook = ExcelHelper.CreateWorkbook(isCompatible, excelFileStream); - foreach (var sheet_item in sheets) + foreach (var sheet_item in numZjExcel.sheets) { if (sheet_item.url.IsNullOrEmpty()) continue; @@ -76,6 +80,7 @@ namespace TempTask.WebEntry.Tools //{ // sheet = workbook.GetSheet(sheet_name.Value); //} + Dictionary dic_sheet_config = new Dictionary(); var api_result = HttpHelper.CallUrl(sheet_item.url.Replace("{year}", year.ToString()).Replace("{_month}", _month).Replace("{week}", week.ToString()).Replace("{week2}", week2), ""); var obj = JObject.Parse(api_result); var datas = obj["data"] as JArray; @@ -103,7 +108,15 @@ namespace TempTask.WebEntry.Tools var column_letter = x.ToExcelColumnName(); if (sheet_item.skip_columns != null && sheet_item.skip_columns.Contains(column_letter)) continue; - var api_column_name = App.Configuration[$"column_name_match_{excelTypeInt}_{sheet_item.sheet_no}:{ x.ToExcelColumnName()}"]; + string api_column_name = string.Empty; + if (numZjExcel.is_excel_config) + { + if (!dic_sheet_config.ContainsKey(column_letter)) + dic_sheet_config.Add(column_letter, sheet.GetRow(startRowIndex).GetCell(x).StringCellValue); + api_column_name = dic_sheet_config[column_letter]; + } + else + api_column_name = App.Configuration[$"column_name_match_{excelTypeInt}_{sheet_item.sheet_no}:{ x.ToExcelColumnName()}"]; if (string.IsNullOrWhiteSpace(api_column_name)) continue; var jtoken = datas[i - current_skip_count][api_column_name]; diff --git a/20220313_Excel/TempTask.WebEntry/Views/Home/Index.cshtml b/20220313_Excel/TempTask.WebEntry/Views/Home/Index.cshtml index d596cf3..a9c5460 100644 --- a/20220313_Excel/TempTask.WebEntry/Views/Home/Index.cshtml +++ b/20220313_Excel/TempTask.WebEntry/Views/Home/Index.cshtml @@ -33,6 +33,7 @@ 总表 城市更新 房地产业 + 通报表格-城市更新0318 @@ -69,6 +70,9 @@ case "3": excel_name = "住建系统抓投资情况通报(房地产业+GDP支撑性指标).xlsx"; break; + case "4": + excel_name = "通报表格(城市更新)2022-3-18.xls"; + break; } this.loading = true; this.download('/api/num-zj/download', a, excel_name, this.loading_false); diff --git a/20220313_Excel/TempTask.WebEntry/new_excel_config/1.xlsx b/20220313_Excel/TempTask.WebEntry/new_excel_config/1.xlsx new file mode 100644 index 0000000..2b48069 Binary files /dev/null and b/20220313_Excel/TempTask.WebEntry/new_excel_config/1.xlsx differ diff --git a/20220313_Excel/TempTask.WebEntry/urlconfig.json b/20220313_Excel/TempTask.WebEntry/urlconfig.json index e99939d..b508152 100644 --- a/20220313_Excel/TempTask.WebEntry/urlconfig.json +++ b/20220313_Excel/TempTask.WebEntry/urlconfig.json @@ -18,8 +18,8 @@ "start_cell": "B", "null_cell_count": 27, "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/totalKeyRate?months={year}{_month}&week={week2}", - "skip_rows": [ 10, 12 ], - + "skip_rows": [ 10, 12 ] + }, { "sheet_no": 2, @@ -52,7 +52,7 @@ "null_row_count": 14, "start_cell": "B", "null_cell_count": 27, - "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/areaKeyRate1?type=104,105,106,107,108,109&months={year}{_month}&week={week2}", + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/areaKeyRate1?type=104,105,106,107,108,109&months={year}{_month}&week={week2}" //"skip_columns": [ "J", "S" ] }, { @@ -95,7 +95,7 @@ "null_row_count": 13, "start_cell": "B", "null_cell_count": 24, - "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/areaKeyRate1?type=101,102,103&months={year}{_month}&week={week2}", + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/areaKeyRate1?type=101,102,103&months={year}{_month}&week={week2}" //"skip_columns": [ "P", "S" ] }, { @@ -162,6 +162,89 @@ "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/houseProjectByArea?months={year}{_month}&w={week}" } ] + }, + { + "excel_no": 4, + "excel_name": "通报表格(城市更新)2022-3-18.xls", + "is_excel_config": true, + "sheets": [ + { + "sheet_no": 1, + "sheet_name": "城市更新" + }, + { + "sheet_no": 2, + "sheet_name": "分行业", + "start_row": 4, + "null_row_count": 7, + "start_cell": "L", + "null_cell_count": 5, + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/projectByInd " + }, + { + "sheet_no": 3, + "sheet_name": "分地区", + "start_row": 4, + "null_row_count": 14, + "start_cell": "L", + "null_cell_count": 5, + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/projectByArea?industry=104,105,106,107,108,109" + }, + { + "sheet_no": 4, + "sheet_name": "未来社区", + "start_row": 4, + "null_row_count": 14, + "start_cell": "L", + "null_cell_count": 5, + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/projectByArea?industry=105" + }, + { + "sheet_no": 5, + "sheet_name": "老旧小区", + "start_row": 4, + "null_row_count": 14, + "start_cell": "L", + "null_cell_count": 5, + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/projectByArea?industry=109" + }, + { + "sheet_no": 6, + "sheet_name": "村镇建设", + "start_row": 4, + "null_row_count": 14, + "start_cell": "L", + "null_cell_count": 5, + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/projectByArea?industry=108" + }, + { + "sheet_no": 7, + "sheet_name": "综合管廊", + "start_row": 4, + "null_row_count": 14, + "start_cell": "L", + "null_cell_count": 5, + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/projectByArea?industry=107" + }, + { + "sheet_no": 8, + "sheet_name": "其他市政设施", + "start_row": 4, + "null_row_count": 14, + "start_cell": "L", + "null_cell_count": 5, + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/projectByArea?industry=104" + }, + { + "sheet_no": 9, + "sheet_name": "城市公园", + "start_row": 4, + "null_row_count": 14, + "start_cell": "L", + "null_cell_count": 5, + "url": "http://10.19.94.196:81/data-system/api/bigScreen/house/projectByArea?industry=106" + } + ] } ] } diff --git a/20220313_Excel/TempTask.WebEntry/wwwroot/ExcelTemplate/OutPut/2022_03_3_总表(样表).xls b/20220313_Excel/TempTask.WebEntry/wwwroot/ExcelTemplate/OutPut/2022_03_3_总表(样表).xls new file mode 100644 index 0000000..85a08ff Binary files /dev/null and b/20220313_Excel/TempTask.WebEntry/wwwroot/ExcelTemplate/OutPut/2022_03_3_总表(样表).xls differ diff --git a/20220313_Excel/TempTask.WebEntry/wwwroot/ExcelTemplate/OutPut/2022_03_3_通报表格(城市更新)2022-3-18.xls b/20220313_Excel/TempTask.WebEntry/wwwroot/ExcelTemplate/OutPut/2022_03_3_通报表格(城市更新)2022-3-18.xls new file mode 100644 index 0000000..3716ad9 Binary files /dev/null and b/20220313_Excel/TempTask.WebEntry/wwwroot/ExcelTemplate/OutPut/2022_03_3_通报表格(城市更新)2022-3-18.xls differ diff --git a/20220313_Excel/TempTask.WebEntry/wwwroot/ExcelTemplate/通报表格(城市更新)2022-3-18.xls b/20220313_Excel/TempTask.WebEntry/wwwroot/ExcelTemplate/通报表格(城市更新)2022-3-18.xls new file mode 100644 index 0000000..9cbeab5 Binary files /dev/null and b/20220313_Excel/TempTask.WebEntry/wwwroot/ExcelTemplate/通报表格(城市更新)2022-3-18.xls differ