TX Text Control系列教程— ASP.NET :报告教程

    ​TX Text Control Server for ASP.NET (incl. WPF)是一个企业级的服务器端文字处理控件。它为用于ASP.NET服务器环境提供一个彻底可编程的文字处理引擎,而且包含一个WPF客户端版本。编程

建立第一个报表应用程序服务器

  1. 打开Visual Studio并建立一个新的ASP.NET空Web应用程序。app

    tutorial_aspnet_reporting_1.png

  2. 在Solution Explorer中,选择项目,而后从项目主菜单中选择Add New Item .... ,在打开的对话框的添加新项目中,选择Web窗体并使用添加确认。工具

    tutorial_aspnet_reporting_2.png

  3. 在Solution Explorer中,选择新建立的Web窗体,而后从View主菜单中选择Component Designer。在工具箱中找到MailMerge组件,而后将实例拖放到组件设计器表单上。而后使用ServerTextControl组件重复此步骤。设计

    tutorial_aspnet_reporting_3.png

  4. 选择MailMerge组件并将TextComponent属性设置为serverTextControl1 - 插入的ServerTextControl实例的名称。3d

    tutorial_aspnet_reporting_4.png

  5. 在解决方案资源管理器中选择项目时,从项目主菜单中选择Add New Item ....,在打开的对话框的添加现有项中,浏览到如下示例文件夹:orm

    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\Tutorialserver

    或者xml

    %USERPROFILE%\Documents\TX Text Control 27.0.NET Server for ASP.NET\Samples\ASP.NET\VB.NET\Documentation Tutorials\MailMerge\Tutorialblog

    选择如下2个文件:template.docx和sample_db.xml,而后单击添加按钮。

    tutorial_aspnet_reporting_5.png

  6. 在Solution Explorer中选择Web Form,而后从View主菜单中选择Designer,在工具箱中找到Button控件,而后将实例拖放到Web窗体上。

    tutorial_aspnet_reporting_6.png

  7. 双击该按钮并将如下代码插入事件处理程序:

    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
  8. 在同一代码视图中,将如下代码添加到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
  9. 编译并启动应用程序。按按钮建立以PDF文件形式返回的报告。

ASP.NET部分使用教程的第一步就完成了,接下来将会介绍AJAX应用程序的建立。

相关文章
相关标签/搜索