TX Text Control Server for ASP.NET (incl. WPF)是一個企業級的服務器端文字處理控件。它爲用於ASP.NET服務器環境提供一個徹底可編程的文字處理引擎,而且包含一個WPF客戶端版本。編程
點擊下載TX Text Control Server for ASP.NET (incl. WPF)最新試用版bash
建立第一個報表應用程序服務器
打開Visual Studio並建立一個新的ASP.NET空Web應用程序。app
在Solution Explorer中,選擇項目,而後從項目主菜單中選擇Add New Item .... ,在打開的對話框的添加新項目中,選擇Web窗體並使用添加確認。 工具
在Solution Explorer中,選擇新建立的Web窗體,而後從View主菜單中選擇Component Designer。在工具箱中找到MailMerge組件,而後將實例拖放到組件設計器表單上。而後使用ServerTextControl組件重複此步驟。ui
選擇MailMerge組件並將TextComponent屬性設置爲serverTextControl1 - 插入的ServerTextControl實例的名稱。spa
在解決方案資源管理器中選擇項目時,從項目主菜單中選擇Add New Item ....,在打開的對話框的添加現有項中,瀏覽到如下示例文件夾:設計
In the opened dialog Add Existing Item, browse to the following sample folder: %USERPROFILE%\Documents\TX Text Control 27.0.NET Server for ASP.NET\Samples\ASP.NET\CSharp\Documentation Tutorials\MailMerge\Tutorialcode
或者orm
%USERPROFILE%\Documents\TX Text Control 27.0.NET Server for ASP.NET\Samples\ASP.NET\VB.NET\Documentation Tutorials\MailMerge\Tutorial
選擇如下2個文件:template.docx和sample_db.xml,而後單擊添加按鈕。
在Solution Explorer中選擇Web Form,而後從View主菜單中選擇Designer,在工具箱中找到Button控件,而後將實例拖放到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複製代碼
編譯並啓動應用程序。按按鈕建立以PDF文件形式返回的報告。
ASP.NET部分使用教程的第一步就完成了,接下來將會介紹AJAX應用程序的建立。