avatar

目录
根据Word模板文件导出简历

根据Word模板文件导出简历

1、需求

有个招聘功能,前端应聘者录入简历表单。如下图:
1

2、实现

新建Word模板文件,需要替换信息的地方插入域来代替。
2

替换后的效果如下:
3

3、编码

添加引用Aspose.Words.dll,添加方法。

Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

public static void CreateJobRequestWord(DataTable JobRequest, bool IsSharpZip) {
string fileName = "";
var docStream = new MemoryStream();
string uploadFilePath = WebUtil.Instance.AppPath() + AppSettingUtil.AppSettings["UploadFilePath"];
string tempPath = HttpContext.Current.Server.MapPath(uploadFilePath + "WordTemplate/Temp.doc");
string folderName = DateTime.Now.ToString("yyyyMMddHHmmssms");
string outputPath = HttpContext.Current.Server.MapPath(uploadFilePath + "jobrequest/" + folderName);
if (JobRequest.Rows.Count == 0) {
return;
}
if (IsSharpZip) {
fileName = DateTime.Now.ToString("yyyyMMddHHmmssms") + ".zip";
}
else {
fileName = JobRequest.Rows[0]["Name"].ToStr() + "_" + JobRequest.Rows[0]["IDCardNo"].ToStr() + "_" + JobRequest.Rows[0]["Whir_U_Jobs_JobRequest_PID"].ToStr() + ".doc";
}
//增加岗位名称
JobRequest.Columns.Add("JobName", typeof(string));
foreach (DataRow dr in JobRequest.Rows) {
docStream = new MemoryStream();
string name = dr["Name"].ToStr() + "_" + dr["IDCardNo"].ToStr() + "_" + dr["Whir_U_Jobs_JobRequest_PID"].ToStr() + ".doc";
var JobName = DbHelper.CurrentDb.ExecuteScalar("select JobName from Whir_U_Jobs where Whir_U_Jobs_PID=@0 and isdel=0", dr["JobID"]).ToStr();
dr["JobName"] = JobName;

int JobRequestId = dr["Whir_U_Jobs_JobRequest_PID"].ToInt(0);

DataTable dtFamily = DbHelper.CurrentDb.Query("select * from Whir_U_Jobs_JobRequest_Family where isdel=0 and JobRequestId=@0", JobRequestId).Tables[0];
dtFamily.TableName = "Family";

DataTable dtLearning = DbHelper.CurrentDb.Query("select * from Whir_U_Jobs_JobRequest_learning where isdel=0 and JobRequestId=@0", JobRequestId).Tables[0];
dtLearning.TableName = "Learning";

DataTable dtSpecialty = DbHelper.CurrentDb.Query("select *,convert(varchar(10),WinningTime,21) as WinningTimeTemp from Whir_U_Jobs_JobRequest_Specialty where isdel=0 and JobRequestId=@0", JobRequestId).Tables[0];
dtSpecialty.TableName = "Specialty";

DataTable dtWorking = DbHelper.CurrentDb.Query("select *,StartEndDate as WorkStartEndDate,Duties as WorkDuties from Whir_U_Jobs_JobRequest_Working where isdel=0 and JobRequestId=@0", JobRequestId).Tables[0];
dtWorking.TableName = "Working";


//----------------------------------------------------------------------------------------------------
var doc = new Document(tempPath);
//头像
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark("Avatar");
try {
builder.InsertImage(HttpContext.Current.Server.MapPath(uploadFilePath + dr["Avatar"].ToStr()), 100, 130);
}
catch (Exception ex) {

}
doc.MailMerge.Execute(dr);
//渲染
doc.MailMerge.ExecuteWithRegions(dtFamily);
doc.MailMerge.ExecuteWithRegions(dtLearning);
doc.MailMerge.ExecuteWithRegions(dtSpecialty);
doc.MailMerge.ExecuteWithRegions(dtWorking);
doc.Save(docStream, Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Doc));
if (IsSharpZip) {
string strFileName = outputPath + "\\" + name;
FileInfo info = new FileInfo(strFileName);
if (!Directory.Exists(info.DirectoryName)) {
Directory.CreateDirectory(info.DirectoryName);
}
doc.Save(strFileName);
}
}
if (IsSharpZip) {
SharpZipHelper szh = new SharpZipHelper();
szh.CompressDirectory(HttpContext.Current.Server.MapPath(uploadFilePath + "jobrequest/" + folderName + "/"), HttpContext.Current.Server.MapPath(uploadFilePath + "jobrequest/" + fileName), 5, 4096);
FileSystemHelper.DeleteFolder(HttpContext.Current.Server.MapPath(uploadFilePath + "jobrequest/" + folderName + "/"));
HttpContext.Current.Response.Redirect(uploadFilePath + "jobrequest/" + fileName);
}
else {
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流 为简体中文
HttpContext.Current.Response.ContentType = "application/ms-word";//设置输出文件类型为excel文件。
HttpContext.Current.Response.BinaryWrite(docStream.ToArray());
HttpContext.Current.Response.End();
}
}

4、效果

4

原文地址:根据Word模板文件导出简历

打赏
  • 微信
    微信
  • 支付寶
    支付寶

评论