TX Text Control Server for ASP.NET (incl. WPF)是一个企业级的服务器端文字处理控件。它为用于ASP.NET服务器环境提供一个完全可编程的文字处理引擎,并且包含一个WPF客户端版本。
点击下载TX Text Control Server for ASP.NET (incl. WPF)最新试用版
创建第一个报表应用程序
-
打开Visual Studio并创建一个新的ASP.NET空Web应用程序。
![tutorial_aspnet_reporting_1.png](https://img7.php1.cn/3cdc5/cc0f/525/0a572bd27a1ed66f.png)
-
在Solution Explorer中,选择项目,然后从项目主菜单中选择Add New Item .... ,在打开的对话框的添加新项目中,选择Web窗体并使用添加确认。
![tutorial_aspnet_reporting_2.png](https://img7.php1.cn/3cdc5/cc0f/525/dab28ce5380a0948.png)
-
在Solution Explorer中,选择新创建的Web窗体,然后从View主菜单中选择Component Designer。在工具箱中找到MailMerge组件,然后将实例拖放到组件设计器表单上。然后使用ServerTextControl组件重复此步骤。
![tutorial_aspnet_reporting_3.png](https://img7.php1.cn/3cdc5/cc0f/525/6347c282f1626607.png)
-
选择MailMerge组件并将TextComponent属性设置为serverTextControl1 - 插入的ServerTextControl实例的名称。
![tutorial_aspnet_reporting_4.png](https://img7.php1.cn/3cdc5/cc0f/525/0888b6cfb18cab6f.png)
-
在解决方案资源管理器中选择项目时,从项目主菜单中选择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\Tutorial
或者
%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,然后单击添加按钮。
![tutorial_aspnet_reporting_5.png](https://img7.php1.cn/3cdc5/cc0f/525/af78e092d51effdf.png)
-
在Solution Explorer中选择Web Form,然后从View主菜单中选择Designer,在工具箱中找到Button控件,然后将实例拖放到Web窗体上。
![tutorial_aspnet_reporting_6.png](https://img7.php1.cn/3cdc5/cc0f/525/19293dd21d0f35d2.png)
-
双击该按钮并将以下代码插入事件处理程序:
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应用程序的创建。