天天看點

根據Word模闆檔案導出履歷

1????姹?

??涓????????斤???绔?搴?????褰??ョ????琛ㄥ????濡?涓??撅?
根據Word模闆檔案導出履歷

2??瀹???/h2>
?闆緩Word妯℃?挎??浠訛???瑕??挎??俊?????版?規???ュ???ヤ唬?褲??
根據Word模闆檔案導出履歷
?挎?㈠????????濡?涓?锛?
根據Word模闆檔案導出履歷

3??缂???

娣誨??寮???spose.Words.dll,娣誨???規???
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<string>("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";//璁劇疆杈??烘??浠剁被??涓?xcel??浠躲??
                HttpContext.Current.Response.BinaryWrite(docStream.ToArray());
                HttpContext.Current.Response.End();
            }
        }
           

4??????

根據Word模闆檔案導出履歷