diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs index 0cd04206..bf0409b3 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs @@ -236,17 +236,17 @@ public class Ghre_ExamServices : BaseServices(sql); - if (toolbars.Any(x => x.fnKey == "NewYN")) - Toolbar.Add(new Toolbar() - { - fnKey = "NewYN", - fnKeyValue = null, - fnTitle = "新增", - fnType = "table", - position = "left", - icon = "ghr-icon-add", - display = true - }); + //if (toolbars.Any(x => x.fnKey == "NewYN")) + // Toolbar.Add(new Toolbar() + // { + // fnKey = "NewYN", + // fnKeyValue = null, + // fnTitle = "新增", + // fnType = "table", + // position = "left", + // icon = "ghr-icon-add", + // display = true + // }); if (param.menuName == "F_ExamManageDraft") Toolbar.Add(new Toolbar() { @@ -270,8 +270,8 @@ public class Ghre_ExamServices : BaseServices x.fnKey == "ToExcelYN")) - Toolbar.Add(toolbars.First(x => x.fnKey == "ToExcelYN")); + //if (toolbars.Any(x => x.fnKey == "ToExcelYN")) + // Toolbar.Add(toolbars.First(x => x.fnKey == "ToExcelYN")); #endregion diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index 6ef47aa7..5a4aac3a 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -1,9 +1,17 @@ using System.Data; using System.Net; using AgileObjects.AgileMapper; +using AgileObjects.AgileMapper.Extensions; using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using NPOI.HSSF.UserModel; +using NPOI.OpenXmlFormats.Spreadsheet; +using NPOI.SS.Formula.Functions; +using NPOI.SS.UserModel; +using NPOI.SS.Util; +using NPOI.XSSF.UserModel; +using SharpCompress.Common; using SqlSugar; using Tiobon.Core.Common; using Tiobon.Core.Common.Caches; @@ -15,6 +23,7 @@ using Tiobon.Core.IServices; using Tiobon.Core.Model; using Tiobon.Core.Model.Models; using Tiobon.Core.Services.BASE; +using static Tiobon.Core.DataAccess.ReportHelper; namespace Tiobon.Core.Services; @@ -1052,9 +1061,103 @@ public class Ghre_QuestionServices : BaseServices(sql); + if (dataSourceLists.Any()) + { + var types = new List + { + "单选题", + "多选题", + "判断题", + "填空题", + "简答题", + }; + + types.ForEach(sheetName => + { + int sheetIndex = hssfworkbook.GetSheetIndex(sheetName); + if (sheetIndex >= 0) + { + sheet = hssfworkbook.GetSheetAt(sheetIndex); + + SetCellDropdownList(sheet, 0, 0, dataSourceLists.Select(x => x.name).ToArray()); + } + + }); + MemoryStream ms; + using (ms = new MemoryStream()) + { + hssfworkbook.Write(ms); + ms.Flush(); + hssfworkbook.Dispose(); + //ms.Position = 0; + //return ms; + } + using (FileStream fs = new FileStream(physicsPath + path + newFileName, FileMode.Create, FileAccess.Write)) + { + byte[] data = ms.ToArray(); + fs.Write(data, 0, data.Length); + fs.Flush(); + } + + } + + var physicsPath1 = physicsPath + path + fileName; + if (dataSourceLists.Any()) + physicsPath1 = physicsPath + path + newFileName; var result = ServiceResult.OprateSuccess(fileName, physicsPath + path + fileName); return result; } + + public static void SetCellDropdownList(ISheet sheet, int firstcol, int lastcol, string[] vals) + { + + //設置生成下拉框的行和列 + var cellRegions = new CellRangeAddressList(1, 65535, firstcol, lastcol); + IDataValidation validation = null; + + if (sheet.GetType().Name.Contains("XSSF")) // .xlsx + { + XSSFDataValidationHelper helper = new XSSFDataValidationHelper((XSSFSheet)sheet);//获得一个数据验证Helper + //IDataValidation + validation = helper.CreateValidation( + helper.CreateExplicitListConstraint(vals), cellRegions);//创建约束 + } + else // HSSF .xls + { + //設置 下拉框內容 + DVConstraint constraint = DVConstraint.CreateExplicitListConstraint(vals); + validation = new HSSFDataValidation(cellRegions, constraint); + + + /*綁定下拉框和作用區域,並設置錯誤提示信息 + HSSFDataValidation dataValidate = new HSSFDataValidation(cellRegions, constraint); + dataValidate.CreateErrorBox("輸入不合法", "請輸入或選擇下拉列表中的值。"); + dataValidate.ShowPromptBox = true; +*/ + } + + validation.CreateErrorBox("输入不合法", "请输入或选择下拉列表中的值。"); + validation.ShowPromptBox = true; + + sheet.AddValidationData(validation); + } + #endregion ///