|
|
|
@ -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<Ghre_Question, Ghre_QuestionDt |
|
|
|
|
|
|
|
|
|
Type entityType = typeof(Ghre_Question); |
|
|
|
|
var fileName = entityType.GetEntityTableName() + ".xlsx"; |
|
|
|
|
//physicsPath = physicsPath + path + fileName; |
|
|
|
|
|
|
|
|
|
IWorkbook hssfworkbook; |
|
|
|
|
ISheet sheet; |
|
|
|
|
using (FileStream file = new FileStream(physicsPath + path + fileName, FileMode.Open, FileAccess.Read)) |
|
|
|
|
{ |
|
|
|
|
//hssfworkbook = new HSSFWorkbook(file); |
|
|
|
|
//hssfworkbook = new XSSFWorkbook(file); |
|
|
|
|
hssfworkbook = WorkbookFactory.Create(file); |
|
|
|
|
} |
|
|
|
|
ISheet sheet2 = hssfworkbook.CreateSheet("下拉数据"); |
|
|
|
|
|
|
|
|
|
var newFileName = Guid.NewGuid() + ".xlsx"; |
|
|
|
|
int listColIndex = 0; |
|
|
|
|
string sql = @"select 'Course' field, Id id, CourseNo no, CourseName name from Ghre_Course where IsEnable=1 and Status='Released'"; |
|
|
|
|
var dataSourceLists = await Db.Ado.SqlQueryAsync<DataSourceList>(sql); |
|
|
|
|
if (dataSourceLists.Any()) |
|
|
|
|
{ |
|
|
|
|
var types = new List<string> |
|
|
|
|
{ |
|
|
|
|
"单选题", |
|
|
|
|
"多选题", |
|
|
|
|
"判断题", |
|
|
|
|
"填空题", |
|
|
|
|
"简答题", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
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<string>.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 |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|