小弟现在项目需要要做一个自定义控件,以girdview为数据源,把数据从数据集里导出分别为execl,txt,xml,html格式的文件保存下来,也就是在自定义控件里写4个方法,对应相应的导出格式,然后在form里分别调用这些方法,导出成excel的已经实现,现在在写导出成txt的遇到个问题,因为girdview本身就是以html形式存在的,在导出成txt文件的时候也把html文件格式的那些标签也给一起导出来了,我只想要数据,请问应该怎么处理这些标签啊?因为下载东西分都用完了,这里没办法给分了,请见谅啊
导出的txt文件的部分内容:
<table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">
<tr>
<th scope="col">ProductID</th><th scope="col">ProductName</th><th scope="col">SupplierID</th><th scope="col">CategoryID</th><th scope="col">QuantityPerUnit</th><th scope="col">UnitPrice</th><th scope="col">UnitsInStock</th><th scope="col">UnitsOnOrder</th><th scope="col">ReorderLevel</th><th scope="col">Discontinued</th><th scope="col">CategoryName</th>
</tr><tr>
<td>1</td><td>Chai</td><td>1</td><td>1</td><td>10 boxes x 20 bags</td><td>18.0000</td><td>39</td><td>0</td><td>10</td><td><span disabled="disabled"><input id="GridView1_ctl74_ctl01" type="checkbox" name="GridView1$ctl74$ctl01" disabled="disabled" /></span></td><td>Beverages</td>我只需要数据内容,不需要<td><tr>这些标签,请问怎么解决这个问题,还有相对应的导出成xml也应该会存在这个问题,又应该怎么解决?请注意啊,方法是写在自定义控件里的,不是在前台窗体里用的‘导出为txt的方法如下:
//fileName 为导出的文件名称,格式为TxT
        public virtual void ExportToTxT(string fileName, Page CurrentPage, Control NtGridView)
        {
            System.Web.UI.HtmlControls.HtmlForm htmlForm = new System.Web.UI.HtmlControls.HtmlForm();
            CurrentPage.Controls.Add(htmlForm);
            htmlForm.Controls.Add(NtGridView);            CurrentPage.Response.Clear();
            CurrentPage.Response.Buffer = true;
            CurrentPage.Response.Charset = "GB2312";            CurrentPage.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
            CurrentPage.Response.ContentType = "text/plain";
            CurrentPage.Response.ContentEncoding = System.Text.Encoding.UTF8;
            CurrentPage.Response.Charset = "";
            CurrentPage.EnableViewState = false;            using (StringWriter stringWriter = new StringWriter())
            {
                HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
                htmlForm.RenderControl(htmlWriter);
                htmlWriter.Flush();                CurrentPage.Response.Write(stringWriter.ToString());
                CurrentPage.Response.End();
            }
        }