在页面上有个表格,表格比较复杂且庞大,就使用了HTML方式,把数据填写在HTML标记写成的表格中。对于没有数据的部分,使用 使得表格线显示出来,而不出现空白,但是使用流的方式导入到EXECL时,EXECL中的格式就会因为有 而变得没有格式。
导出的代码如下:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myCItrad As System.Globalization.CultureInfo
Dim oStringWriter As System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter
Response.Clear()
Response.Buffer = True
Response.Charset = "GB2312"
Response.AppendHeader("Content-Disposition", "attachment;filename=Filename.xls")
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
Response.ContentType = "application/ms-excel"
Me.EnableViewState = False
myCItrad = New System.Globalization.CultureInfo("ZH-CN", True)
oStringWriter = New System.IO.StringWriter(myCItrad)
oHtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
Me.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.End()
End Sub请问,如何解决页面上看起来不缺失表格线,导入EXECL又能按照页面上的表现格式导入。
导出的代码如下:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myCItrad As System.Globalization.CultureInfo
Dim oStringWriter As System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter
Response.Clear()
Response.Buffer = True
Response.Charset = "GB2312"
Response.AppendHeader("Content-Disposition", "attachment;filename=Filename.xls")
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
Response.ContentType = "application/ms-excel"
Me.EnableViewState = False
myCItrad = New System.Globalization.CultureInfo("ZH-CN", True)
oStringWriter = New System.IO.StringWriter(myCItrad)
oHtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
Me.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.End()
End Sub请问,如何解决页面上看起来不缺失表格线,导入EXECL又能按照页面上的表现格式导入。
public static void GridView_Export_Excel(GridView GV,string FileName,string Title_str)
{ //将指定的GridView中数据导出带标题的EXCEL文件 StringBulid sb=new StringBuild();
StringWriter sw=new StringWriter(sb);
HtmlTextWriter htw=new HtmlTextWriter(sw);
Page page=new Page();
HtmlForm form=new HtmlForm();
GV.enableViewState=false;
page.EnableEvenValidation=false
page.DesignerInitialize();
page.Controls.Add(form);
page.Controls.Add(GV);
page.RenderControl(htw);
...... //其他的就是利用Response,相信你知道该如何了。}
表格设置
<table border="1" id="table3" cellspacing="1" bordercolorlight="#000000" cellpadding="0" bordercolor="#000000" style="border-collapse:collapse">
主要的就是 cellspacing="1"、bordercolorlight="#000000"以及border-collapse:collapse,这样在页面上显示时候,如果从数据库中读出的为空,页面上也可以画出表格线,那么就省去了在空单元格内写 ,那么在导出的时候就避免了这些问题。