|
|
@ -24,7 +24,15 @@ namespace DS.Module.ExcelModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
|
|
|
static readonly ApiFox api;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 构造函数
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
|
|
|
static ExcelService()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
api = new ApiFox();
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 构造函数
|
|
|
|
/// 构造函数
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -33,7 +41,6 @@ namespace DS.Module.ExcelModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public DataResult<string> ExportExcelByColumn(ExportByColumnReq req)
|
|
|
|
public DataResult<string> ExportExcelByColumn(ExportByColumnReq req)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -60,6 +67,29 @@ namespace DS.Module.ExcelModule
|
|
|
|
return DataResult<string>.Success(path);
|
|
|
|
return DataResult<string>.Success(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<MemoryStream> ExportExcelStreamByColumnAsync(ExportByColumnReq req)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var data = JArray.Parse(req.JsonDataStr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var values = new List<Dictionary<string, object>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < data.Count; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var temp = data[i];
|
|
|
|
|
|
|
|
var info = new Dictionary<string, object>();
|
|
|
|
|
|
|
|
for (int n = 0; n < req.ColumnSets.Count; n++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var columnSet = req.ColumnSets[n];
|
|
|
|
|
|
|
|
var key = columnSet.DataIndex;
|
|
|
|
|
|
|
|
info.Add(columnSet.Title, temp[key]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
values.Add(info);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var stream = new MemoryStream();
|
|
|
|
|
|
|
|
await MiniExcel.SaveAsAsync(stream, values);
|
|
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MemoryStream ExportExcelStreamByColumn(ExportByColumnReq req)
|
|
|
|
public MemoryStream ExportExcelStreamByColumn(ExportByColumnReq req)
|
|
|
|
{
|
|
|
|
{
|
|
|
|