用Magicodes.IE.Pdf导出数据列表,原代码不是一个集合,被我改为list之后报错,求正确方法。
报错如下:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“Cannot implicitly convert type 'Magicodes.ExporterAndImporter.Core.Models.ExportDocumentInfo<System.Collections.Generic.List<WebApplication1.Person>>' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)”
public async Task<FileResult> Export()
{
try
{
Person resumeDescription1 = new Person
{
Id = 1,
Name = "张三",
Gender = "男",
Birthday = Convert.ToDateTime("1995-05-22"),
Mobile = "18888888888",
University = "华中科技大学",
Education = "硕士研究生",
Major = "计算机科学技术",
Nation = "汉族",
MarriageStaus = "已婚",
Occupation = "砖厂搬砖",
FreshStudent = "否",
VisitDate = Convert.ToDateTime("2017-07-01"),
CurrentCompanyName = "王多鱼谁有梦想投资有限公司",
Resignation = "梦想都实现了,现想找一份端茶调水双休五险一金不是996的软件公司",
Profile = "本人精通Word、Excel、Access、Power Point、Outlook Express等软件的安装与卸载 熟练掌握VB、C++、FoxPro、SQL、java 等单词的拼写熟悉 Win7、WindowsPhone、Linux、Mac、Android、IOS、Blackberry等操作系统的开关机!",
Evaluate = "C#是世界上最好的语言",
FurImg = $"{_webHostEnvironment.WebRootPath}\\Images\\001.jpg",
AnalysisReport = $"{_webHostEnvironment.WebRootPath}\\Images\\002.jpg"
};
Person resumeDescription2 = new Person
{
Id = 1,
Name = "张三",
Gender = "男",
Birthday = Convert.ToDateTime("1995-05-22"),
Mobile = "18888888888",
University = "华中科技大学",
Education = "硕士研究生",
Major = "计算机科学技术",
Nation = "汉族",
MarriageStaus = "已婚",
Occupation = "砖厂搬砖",
FreshStudent = "否",
VisitDate = Convert.ToDateTime("2017-07-01"),
CurrentCompanyName = "王多鱼谁有梦想投资有限公司",
Resignation = "梦想都实现了,现想找一份端茶调水双休五险一金不是996的软件公司",
Profile = "本人精通Word、Excel、Access、Power Point、Outlook Express等软件的安装与卸载 熟练掌握VB、C++、FoxPro、SQL、java 等单词的拼写熟悉 Win7、WindowsPhone、Linux、Mac、Android、IOS、Blackberry等操作系统的开关机!",
Evaluate = "C#是世界上最好的语言",
FurImg = $"{_webHostEnvironment.WebRootPath}\\Images\\001.jpg",
AnalysisReport = $"{_webHostEnvironment.WebRootPath}\\Images\\002.jpg"
};
List<Person> people = new List<Person>();
people.Add(resumeDescription1);
people.Add(resumeDescription2);
var tplPath = Path.Combine(Directory.GetCurrentDirectory(), "Template", "PdfTemplate.cshtml");
var tpl = System.IO.File.ReadAllText(tplPath);
var exporter = new PdfExporter();
string fileName = $"{Guid.NewGuid().ToString()}.pdf";
string downloadName = $"{Path.Combine(Directory.GetCurrentDirectory())}\\{fileName}";
var result = await exporter.ExportByTemplate(downloadName,
people, tpl);
//因为生成的模板默认在当前项目下,需要移动到wwwroot
System.IO.File.Move(result.FileName, $"{_webHostEnvironment.WebRootPath}\\Download\\{fileName}");
string addrUrl = $"{_webHostEnvironment.WebRootPath}\\Download\\{fileName}";
var stream = System.IO.File.OpenRead(addrUrl);
return File(stream, result.FileType, Path.GetFileName(addrUrl));
}
catch (Exception ex)
{
var stream = System.IO.File.OpenRead(null);
return File(stream, "application/vnd.android.package-archive");
}
}
@using WebApplication1
<!DOCTYPE html>
<html>
@model List<Person>
<head>
<meta charset='UTF-8'>
<title></title>
<style>
body {
margin: 0;
padding: 0;
min-width: 1080px;
}
.m_table {
border-collapse: separate;
margin: 20px auto 0;
min-width: 1900px;
text-align: center;
font: 500 17px '微软雅黑';
border-spacing: 0;
border: 1px solid #EBEEF5;
}
.m_table th {
background-color: #F7F3F7;
}
.m_table th,
.m_table td {
border-right: 1px solid #EBEEF5;
border-bottom: 1px solid #EBEEF5;
padding: 5px;
height: 60px;
width: 60px;
}
</style>
</head>
<body>
<table class='m_table'>
<tr>
<th colspan='8' style='text-align:left;font-size:18px;'>个人信息</th>
</tr>
@foreach(var person in Model)
{
<tr>
<td> 姓名:</td>
<td> @person.Name </td>
<td> 性别: </td>
<td> @person.Gender </td>
<!-- 其他属性类似 -->
</tr>
}
</table>
</body>
</html>
[Exporter(Name = "个人简历")]
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public DateTime Birthday { get; set; }
public string Mobile { get; set; }
public string University { get; set; }
public string Education { get; set; }
public string Major { get; set; }
public string Nation { get; set; }
public string MarriageStaus { get; set; }
public string Occupation { get; set; }
public string FreshStudent { get; set; }
public DateTime VisitDate { get; set; }
public string CurrentCompanyName { get; set; }
public string Resignation { get; set; }
public string Profile { get; set; }
public string Evaluate { get; set; }
public string FurImg { get; set; }
public string AnalysisReport { get; set; }
}