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

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

ASP.NET導出word文檔并下載

發表日期:2017-10-19    文章編輯:南昌開優網絡    瀏覽次數:5321    標簽: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();
} 
主站蜘蛛池模板: 呼图壁县| 晋宁县| 化隆| 西昌市| 石家庄市| 顺平县| 横山县| 贡觉县| 巴东县| 阳泉市| 上林县| 万年县| 云安县| 鹿邑县| 盐津县| 新邵县| 岳阳县| 海宁市| 方山县| 武穴市| 石狮市| 申扎县| 永州市| 林周县| 阿拉善右旗| 浪卡子县| 永康市| 泾川县| 兴海县| 蓬安县| 华容县| 慈利县| 长垣县| 曲水县| 祁门县| 福清市| 左云县| 丹阳市| 辉南县| 安龙县| 新津县|