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

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

                                     点击下载TX Text Control Server for ASP.NET (incl. WPF)最新试用版


创建第一个报表应用程序

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

    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实例的名称。

    tutorial_aspnet_reporting_4.png

  5. 在解决方案资源管理器中选择项目时,从项目主菜单中选择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

  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应用程序的创建。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值