翻譯|使用教程|編輯:況魚杰|2019-08-05 15:50:38.567|閱讀 401 次
概述:本教程將會介紹如何使用ASP.NET Web應(yīng)用程序中的MailMerge組件將模板與數(shù)據(jù)合并以創(chuàng)建Adobe PDF文檔。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
TX Text Control Server for ASP.NET (incl. WPF)是一個(gè)企業(yè)級的服務(wù)器端文字處理控件。它為用于ASP.NET服務(wù)器環(huán)境提供一個(gè)完全可編程的文字處理引擎,并且包含一個(gè)WPF客戶端版本。
點(diǎn)擊下載TX Text Control Server for ASP.NET (incl. WPF)最新試用版
創(chuàng)建第一個(gè)報(bào)表應(yīng)用程序
打開Visual Studio并創(chuàng)建一個(gè)新的ASP.NET空Web應(yīng)用程序。
在Solution Explorer中,選擇項(xiàng)目,然后從項(xiàng)目主菜單中選擇Add New Item .... ,在打開的對話框的添加新項(xiàng)目中,選擇Web窗體并使用添加確認(rèn)。
在Solution Explorer中,選擇新創(chuàng)建的Web窗體,然后從View主菜單中選擇Component Designer。在工具箱中找到MailMerge組件,然后將實(shí)例拖放到組件設(shè)計(jì)器表單上。然后使用ServerTextControl組件重復(fù)此步驟。
選擇MailMerge組件并將TextComponent屬性設(shè)置為serverTextControl1 - 插入的ServerTextControl實(shí)例的名稱。
在解決方案資源管理器中選擇項(xiàng)目時(shí),從項(xiàng)目主菜單中選擇Add New Item ....,在打開的對話框的添加現(xiàn)有項(xiàng)中,瀏覽到以下示例文件夾:
%USERPROFILE%\Documents\TX Text Control 27.0.NET Server for ASP.NET\Samples\ASP.NET\CSharp(或者VB.NET)\Documentation Tutorials\MailMerge\Tutorial
選擇以下2個(gè)文件:template.docx和sample_db.xml,然后單擊添加按鈕。
在Solution Explorer中選擇Web Form,然后從View主菜單中選擇Designer,在工具箱中找到Button控件,然后將實(shí)例拖放到Web窗體上。
雙擊該按鈕并將以下代碼插入事件處理程序:
CS:
protected void Button1_Click(object sender, EventArgs e) { // create a DataSet from the sample XML data source System.Data.DataSet ds = new System.Data.DataSet(); ds.ReadXml(Server.MapPath("sample_db.xml"), System.Data.XmlReadMode.Auto); // load the template mailMerge1.LoadTemplate(Server.MapPath("template.docx"), TXTextControl.DocumentServer.FileFormat.WordprocessingML); // merge the template with data mailMerge1.Merge(ds.Tables[0]); // save the document as PDF into a byte array byte[] data; mailMerge1.SaveDocumentToMemory(out data, TXTextControl.BinaryStreamType.AdobePDF, null); // return the document to the browser for download Response.Clear(); Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", "created_by_txtextcontrol.pdf")); Response.ContentType = "application/pdf"; Response.BinaryWrite(data); Response.End(); } Sign up for free
VB:
Protected Sub Button1_Click(sender As Object, e As EventArgs) ' create a DataSet from the sample XML data source Dim ds As New System.Data.DataSet() ds.ReadXml(Server.MapPath("sample_db.xml"), System.Data.XmlReadMode.Auto) ' load the template mailMerge1.LoadTemplate(Server.MapPath("template.docx"), TXTextControl.DocumentServer.FileFormat.WordprocessingML) ' merge the template with data mailMerge1.Merge(ds.Tables(0)) ' save the document as PDF into a byte array Dim data As Byte() mailMerge1.SaveDocumentToMemory(data, TXTextControl.BinaryStreamType.AdobePDF, Nothing) ' return the document to the browser for download Response.Clear() Response.AddHeader("content-disposition", [String].Format("attachment;filename={0}", "created_by_txtextcontrol.pdf")) Response.ContentType = "application/pdf" Response.BinaryWrite(data) Response.[End]() End Sub
在同一代碼視圖中,將以下代碼添加到Page_Load事件:
CS:
protected void Page_Load(object sender, EventArgs e) { InitializeComponent(); }
VB:
Protected Sub Page_Load(sender As Object, e As EventArgs) InitializeComponent() End Sub
編譯并啟動(dòng)應(yīng)用程序。按按鈕創(chuàng)建以PDF文件形式返回的報(bào)告。
ASP.NET部分使用教程的第一步就完成了,接下來將會介紹AJAX應(yīng)用程序的創(chuàng)建。
關(guān)注慧聚IT微信公眾號 ???,了解產(chǎn)品的最新動(dòng)態(tài)及最新資訊。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: