master
ZR20090193-陈敬勇 7 months ago
parent eadb9a7b80
commit 8175fb1312

@ -47,36 +47,40 @@ namespace DS.Module.ExcelModule
for (int n = 0; n < req.ColumnSets.Count; n++)
{
var columnSet = req.ColumnSets[n];
var key = columnSet.DataIndex;
// var info = new Dictionary<string, object>
//{
// { columnSet.Title, temp[key] },
//};
var key = columnSet.DataIndex;
info.Add(columnSet.Title, temp[key]);
}
values.Add(info);
}
MiniExcel.SaveAs(path, values);
return DataResult<string>.Success(path);
//var memoryStream = new MemoryStream();
//memoryStream.SaveAs(values);
//memoryStream.Seek(0, SeekOrigin.Begin);
//return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
//{
// FileDownloadName = filename
//};
//using (var memoryStream = new MemoryStream())
//{
// memoryStream.SaveAs(values);
// memoryStream.Seek(0, SeekOrigin.Begin);
// return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
// {
// FileDownloadName = filename
// };
//}
//MiniExcel.SaveAs(path, values);
}
//throw new NotImplementedException();
public MemoryStream ExportExcelStreamByColumn(ExportByColumnReq req)
{
var filename = Guid.NewGuid() + ".xlsx";
//var path = Path.Combine(_environment.WebRootPath, "export/" + filename);
var path = Path.Combine("", "wwwroot/export/" + filename);
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 memoryStream = new MemoryStream();
memoryStream.SaveAs(values);
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
}
}

@ -17,5 +17,12 @@ namespace DS.Module.ExcelModule
/// <param name="req">请求数据</param>
/// <returns></returns>
public DataResult<string> ExportExcelByColumn(ExportByColumnReq req);
/// <summary>
///
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public MemoryStream ExportExcelStreamByColumn(ExportByColumnReq req);
}
}

@ -34,5 +34,17 @@ namespace DS.WMS.MainApi.Controllers
{
return _invokeService.ExportExcelByColumn(req);
}
/// <summary>
/// 根据用户列导出Excel文件流
/// </summary>
/// <param name="req">请求数据</param>
/// <returns></returns>
[HttpPost]
[Route("ExportExcelStreamByColumn")]
public FileStreamResult ExportExcelStreamByColumn([FromBody] ExportByColumnReq req)
{
return _invokeService.ExportExcelStreamByColumn(req);
}
}
}

@ -1188,3 +1188,10 @@
2024-04-12 16:21:31.6323 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.MainApi\bin\Debug\net8.0\nlog.config
2024-04-12 16:21:31.6622 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-04-12 16:21:31.7061 Info Configuration initialized.
2024-04-12 16:48:49.6283 Info Registered target NLog.Targets.FileTarget(Name=allfile)
2024-04-12 16:48:49.7407 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web)
2024-04-12 16:48:49.7627 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console)
2024-04-12 16:48:49.9654 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False
2024-04-12 16:48:50.0016 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.MainApi\bin\Debug\net8.0\nlog.config
2024-04-12 16:48:50.0259 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile
2024-04-12 16:48:50.0613 Info Configuration initialized.

@ -8,6 +8,7 @@ using DS.WMS.Core.System.Entity;
using DS.WMS.Core.System.Interface;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Ocsp;
using SqlSugar;
using SqlSugar.IOC;
using Xunit;
@ -52,16 +53,14 @@ public class ExcelTest
for (int i = 0; i < data.Count; i++)
{
var temp = data[i];
var info = new Dictionary<string, object>();
for (int n = 0; n < set.Count; n++)
{
var columnSet = set[n];
var key = columnSet.DataIndex;
var info = new Dictionary<string, object>
{
{ columnSet.Title, temp[key] },
};
values.Add(info);
info.Add(columnSet.Title, temp[key]);
}
values.Add(info);
}
Console.WriteLine(values);
Assert.True(true);

Loading…
Cancel
Save