private void ShowWordDoc() { string sFile_Source; string sFilename_Download; string s1; StringBuilder sResult = new StringBuilder(); if (!Entry_Query()) { ShowQueryError(msPageErrorMsg); return; } sFile_Source = Server.MapPath("./WordTemplate/" + mcsPgmID + ".xml"); if (!File.Exists(sFile_Source)) { s1 = string.Format("找不到範本檔案{0}.", sFile_Source); ShowQueryError(s1); return; } lblMsg_InBrowse.Text = ""; pnlBrowseEntry.Visible = true; this.btnPrint.Visible = true; sFilename_Download = string.Format("{0}-{1}.doc", mcsPgmID, DateTime.Now.ToString("yyyyMMdd-HHmmss")); sResult.Length = 0; using (StreamReader sr = new StreamReader(sFile_Source, Encoding.UTF8)) { sResult.Append(sr.ReadToEnd()); } sResult.Replace("E.ExecNO", mspE_ExecNO); sResult.Replace("P.SndTime", mspP_SndTime); sResult.Replace("P.SndDocCounte", mspP_SndDocCounte ); sResult.Replace("P.ExecNam", mspP_ExecNam); sResult.Replace("P.BirthDay", mspP_BirthDay); sResult.Replace("P.SexID", mspP_SexID); sResult.Replace("P.WorkNam", mspP_WorkNam ); sResult.Replace("P.Exec_NO", mspP_Exec_NO); sResult.Replace("P.Addr1", mspP_Addr1); sResult.Replace("P.AltExecNam", mspP_AltExecNam); sResult.Replace("P.AltBirthDay", mspP_AltBirthDay); sResult.Replace("P.AltSexID", mspP_AltSexID); sResult.Replace("P.AltWorkNam", mspP_AltWorkNam); sResult.Replace("P.AltExec_NO", mspP_AltExec_NO); sResult.Replace("P.AltAddr1", mspP_AltAddr1); sResult.Replace("E.RegTime", mspE_RegTime); sResult.Replace("P.Is_Exec", mspP_Is_Exec); sResult.Replace("P.CheckDate", mspP_CheckDate); sResult.Replace("P.ReaDate", mspP_ReaDate); sResult.Replace("P.Reason2", mspP_Reason2); sResult.Replace("P.PayDeadLine1", mspP_PayDeadLine1); // 長的先換掉 sResult.Replace("P.PayDeadLine", mspP_PayDeadLine); sResult.Replace("P.PayCount", mspP_PayCount); sResult.Replace("P.Reason1", mspP_Reason1); sResult.Replace("P.Attach7", mspP_Attach7); sResult.Replace("P.Attach8", mspP_Attach8); sResult.Replace("P.StatusString", mspP_StatusString); // Write output Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=" + sFilename_Download);//word檔名 Response.ContentType = "application/vnd.ms-word"; Response.Charset = ""; Response.Write(sResult.ToString()); Response.End(); }