专业制作网站的公司,建行手机银行app下载,0791网站建设,成都教育网站建设公司价格原文作者#xff1a;HueiFeng前言在2.2里程碑中我们增加了一些新的功能,正如标题所写通过请求头进行导出我们不同格式的文件.下面我们来看一下如何使用.通过这种方式无论是对我们的数据多用途#xff0c;还是说对我们的数据校验都做到了轻松易配。同时我们也将在本周发布2.3版… 原文作者HueiFeng前言在2.2里程碑中我们增加了一些新的功能,正如标题所写通过请求头进行导出我们不同格式的文件.下面我们来看一下如何使用.通过这种方式无论是对我们的数据多用途还是说对我们的数据校验都做到了轻松易配。同时我们也将在本周发布2.3版本另外3.0版本我们将进行一次大的性能提升。3.0版本我们将对Razor引擎以及导出引擎进行更换包括对所有代码的重构这是值得期待的。上周我们发布了2.2.5版本更新如下【Nuget】版本更新到2.2.5【Excel导出】增加分栏、分sheet、追加rows导出 #74- exporter.Append(list1).SeparateByColumn().Append(list2).ExportAppendData(filePath);
- exporter.Append(list1).SeparateBySheet().Append(list2).ExportAppendData(filePath);
- exporter.Append(list1).SeparateByRow().AppendHeaders().Append(list2).ExportAppendData(filePath);
[Excel导出】修复‘IsAllowRepeattrue’ #107[Pdf导出】增加PDF扩展方法支持通过以参数形式传递特性参数 #104- Taskbyte[] ExportListBytesByTemplateT(ICollectionT data, PdfExporterAttribute pdfExporterAttribute,string temple);
- Taskbyte[] ExportBytesByTemplateT(T data, PdfExporterAttribute pdfExporterAttribute,string template);
主要步骤01安装包Install-Package Magicodes.IE.AspNetCore
02开始配置在Startup.cs的Configure()方法中,在UseRouting()中间件之后,注册如下中间件public void Configure(IApplicationBuilder app)
{app.UseRouting();app.UseMagiCodesIE();app.UseEndpoints(endpoints {endpoints.MapControllers();});
}
上面这种以中间件形式可以为我们提供导出服务那么我们再看一下另一种方式如下所示 public void ConfigureServices(IServiceCollection services){services.AddControllers(optionsoptions.Filters.Add(typeof(MagicodesFilter)));}
上面两种方式都可以为我们提供导出服务我们只需要对我们的控制器进行配置我们的特性在这边呢 特性主要做的是一个标识作用标识他的一些相关的内容数据同时标识他可以当成文件导出。[HttpGet(excel)]
[Magicodes(Type typeof(ExportTestDataWithAttrs))]
public ListExportTestDataWithAttrs Excel()
{return GenFu.GenFu.ListOfExportTestDataWithAttrs(100);
}
上面代码片段中我们标识这个类允许被导出。同时我们需要通过Type指定我们被导出类的类型。这样填写完后我们可以通过对该地址的调用但是注意我们必须要添加请求头以标识被导出的文件类型。如果不添加请求头那么此处将返回的还是json格式的数据。请求头名称为Magicodes-Type/// summary/// XLSX/// /summaryinternal const string XLSXHttpContentMediaType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;/// summary/// PDF/// /summaryinternal const string PDFHttpContentMediaType application/pdf;/// summary/// DOCX/// /summaryinternal const string DOCXHttpContentMediaType application/vnd.openxmlformats-officedocument.wordprocessingml.document;/// summary/// HTML/// /summaryinternal const string HTMLHttpContentMediaType text/html;
如果说是模板导出word或者pdf甚至说html文件那么我们也是同样的操作如下所示[HttpGet(Word)][Magicodes(Type typeof(ReceiptInfo), TemplatePath .//ExportTemplates//receipt.cshtml)]public ReceiptInfo Word(){return new ReceiptInfo{Amount 22939.43M,Grade 2019秋,IdNo 43062619890622xxxx,Name 张三,Payee 湖南心莱信息科技有限公司,PaymentMethod 微信支付,Profession 运动训练,Remark 学费,TradeStatus 已完成,TradeTime DateTime.Now,UppercaseAmount 贰万贰仟玖佰叁拾玖圆肆角叁分,Code 19071800001};}
我们还是需要对其指定Type然后通过TemplatePath进行指定模板地址即可同样的我们还可以通过请求头进行标识本次请求是否是文件格式导出。[HttpGet(pdf)][Magicodes(Type typeof(BatchPortraitReceiptInfoInput), TemplatePath .//ExportTemplates//batchReceipt.cshtml)]public BatchPortraitReceiptInfoInput Pdf(){var input new BatchPortraitReceiptInfoInput{Payee 湖南心莱信息科技有限公司,SealUrl data:image/jpeg;base64....,LogoUrl data:image/png;base64....,ReceiptInfoInputs new ListBatchPortraitReceiptInfoDto()};for (var i 0; i 500; i)input.ReceiptInfoInputs.Add(new BatchPortraitReceiptInfoDto{Amount 22939.43M,Grade 2019秋,IdNo 43062619890622xxxx,Name 张三,PaymentMethod 微信支付,Profession 运动训练,Remark 学费,TradeStatus 已完成,TradeTime DateTime.Now,UppercaseAmount 贰万贰仟玖佰叁拾玖圆肆角叁分,Code 1907180000 i});return input;}[HttpGet(Html)][Magicodes(Type typeof(ReceiptInfo), TemplatePath .//ExportTemplates//receipt.cshtml)]public ReceiptInfo Html(){return new ReceiptInfo{Amount 22939.43M,Grade 2019秋,IdNo 43062619890622xxxx,Name 张三,Payee 湖南心莱信息科技有限公司,PaymentMethod 微信支付,Profession 运动训练,Remark 学费,TradeStatus 已完成,TradeTime DateTime.Now,UppercaseAmount 贰万贰仟玖佰叁拾玖圆肆角叁分,Code 19071800001};}
Referencehttps://github.com/dotnetcore/Magicodes.IE