欧美日韩一区二区三区四区不卡,日韩欧美视频一区二区三区四区,久久精品欧美一区二区三区不卡,国产精品久久久乱弄

咨詢電話:186 7916 6165 咨詢電話:186 7916 6165 (微信同號)    在線QQ:181796286
NEWS BLOG ·
學無止境
關注開優網絡 關注前沿
ASP.NET MVC分頁設置
.NET 三種取整方法 向上取整 向下取整 四舍五入

ASP.NET導出word文檔并下載

發表日期:2017-10-19    文章編輯:南昌開優網絡    瀏覽次數:5337    標簽:ASP.NET應用

//按鈕生成事件
protected void Button1_Click(object sender, EventArgs e)  
{
	string number = "2017101600001";//編號 	//number是對應word中的number標簽
	string createdate = "2017-10-16";//日期  	//createdate是對應word中的number標簽
	string title = "文章標題文章標題";//標題 		//title 是對應word中的title 標簽
	string username = "管理員姓名";//名稱           	//username 是對應word中的username 標簽
	OutWord(number, createdate, title, username);    //生成事件
}
//生成word文檔
public void OutWord(string number, string createdate, string title, string username)
{ 
//定義word文檔,含標簽
	string docmb = System.Web.HttpContext.Current.Server.MapPath("/upload/template.doc");
	Document doc = new Document(docmb); //引用Aspose.Words.dll第三方類
	doc.Range.Bookmarks["number"].Text = number;  //寫入標簽中的值
	doc.Range.Bookmarks["createdate"].Text = createdate;
	doc.Range.Bookmarks["title"].Text = title;
	doc.Range.Bookmarks["username"].Text = username;           
	string Create = DateTime.Now.ToString("yyyyMMddhhmmss");
	string savepath = System.Web.HttpContext.Current.Server.MapPath("/upload/網上信息公開申請表.doc");//新文檔路徑  
	doc.Save(savepath);//保存文件
	FileDown(savepath);//下載
}
/// <summary>
/// 文件下載
/// </summary>
/// <param name="filepath"></param>
public void FileDown(string filepath)
{
	FileInfo fi = new FileInfo(filepath);
	HttpContext.Current.Response.Clear();
	HttpContext.Current.Response.ClearHeaders();
	HttpContext.Current.Response.Buffer = false;
	HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(filepath), System.Text.Encoding.UTF8)); //輸入文檔流
	HttpContext.Current.Response.AppendHeader("Content-Length", fi.Length.ToString());
	HttpContext.Current.Response.ContentType = "application/octet-stream"; //定義格式
	HttpContext.Current.Response.WriteFile(filepath);  //下載文件
	HttpContext.Current.Response.Flush();
	HttpContext.Current.Response.End();
} 
主站蜘蛛池模板: 雷山县| 肃南| 惠东县| 张掖市| 余干县| 西林县| 左云县| 高碑店市| 屏东县| 鄯善县| 紫云| 道真| 上虞市| 霍林郭勒市| 锦屏县| 新泰市| 新宾| 凉城县| 新津县| 武义县| 平山县| 云安县| 屏边| 建阳市| 凤庆县| 霍林郭勒市| 南岸区| 晋城| 安阳县| 白河县| 桦川县| 白山市| 泸州市| 余干县| 富阳市| 黑山县| 子洲县| 江口县| 洪湖市| 枣庄市| 辽宁省|