推荐使用两个第三方库:
1, ReportViewerCore.NETCore
2, AspNetCore.Reporting
以上两个使用起来都很方便,且能很快转成pdf等格式的文件
ReportViewerCore.NETCore 使用代码
Stream reportDefinition = new FileStream(fileName, FileMode.Open, FileAccess.Read);
LocalReport report = new LocalReport();
report.LoadReportDefinition(reportDefinition);
report.DataSources.Add(new ReportDataSource("DT1", dt2));
byte[] bytes = report.Render(fileType);
FileStream fs = new FileStream(reportFile, FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
fs.Dispose();
AspNetCore.Reporting 使用代码
LocalReport report = new LocalReport(FileName);
report.AddDataSource("DT1", dt2); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
//Encoding.GetEncoding("windows-1252");
Encoding.GetEncoding("utf-8");
var result = report.Execute(GetRenderType(FileType), 1);
var bytes = result.MainStream;
FileStream fs = new FileStream(ReportFile, FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
fs.Dispose();