当我使用网格导出为excel时,我不想在我的Excel中显示边框 [英] I dont want to show borders in my excel when i use grid for export to excel
问题描述
System.IO.StringWriter sw = new System.IO.StringWriter();
foreach(数据表dt in ds.Tables)
{
GridView grd = new GridView();
grd.DataSource = dt;
< br $>
grd.Style.Remove(border-collapse);
grd.Attributes.Remove(style);
grd.Attributes.Remove(border);
grd.Attributes.Add(style,display:none;);
grd.DataBind();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grd.RenderControl(htw);
grd = null;
}
在上面的代码我将数据表作为源传递给gridview
当我快速观察htw它返回结果为下面: -
base {System.IO.TextWriter} = {< div >
< 表 cellspacing = 0 rules = all border = 1 style = border-collapse:collapse; display:none; >
< tr >
< th 范围 = col > ; idUsr < / th > < th < span class =code-attribute> scope = col > cdCode < / th > < th 范围 = col > idGrp < / th > < th 范围 = col > sNamePrefix < < span class =code-leadattribute> / th > < th scope = col > sNameFirst < / th > ...
这个默认的边框属性和样式添加到表中如何从表结构中删除它?请帮助!
尝试类似
grd.RowStyle.CssClass = BorderClass;
grd.ItemStyle.CssClass = BorderClass;
Css类:
<前lang =cs> .BorderClass
{
border-style:none;
}
希望这会有所帮助......
grd.Gridlines = Gridlines 。没有;
grd.RowStyle.BorderStyle = BorderStyle.None;
grd.RowStyle.BorderWidth = Unit.Pixel(0);
System.IO.StringWriter sw = new System.IO.StringWriter();
foreach (DataTable dt in ds.Tables)
{
GridView grd = new GridView();
grd.DataSource = dt;
grd.Style.Remove("border-collapse");
grd.Attributes.Remove("style");
grd.Attributes.Remove("border");
grd.Attributes.Add("style", "display:none;");
grd.DataBind();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grd.RenderControl(htw);
grd = null;
}
In this above code im passing datatable as source to gridview
when i quick watch on htw it return result as below:-
base {System.IO.TextWriter} = {<div>
<table cellspacing="0" rules="all" border="1" style="border-collapse:collapse;display:none;">
<tr>
<th scope="col">idUsr</th><th scope="col">cdCode</th><th scope="col">idGrp</th><th scope="col">sNamePrefix</th><th scope="col">sNameFirst</th>...
in this by default border attribute and style added to table how could i remove this from table structure?Please Help!
Try something like
grd.RowStyle.CssClass = "BorderClass"; grd.ItemStyle.CssClass = "BorderClass";
Css Class:
.BorderClass { border-style:none; }
Hope this helps...
grd.Gridlines=Gridlines.None;
grd.RowStyle.BorderStyle = BorderStyle.None;
grd.RowStyle.BorderWidth = Unit.Pixel(0);
这篇关于当我使用网格导出为excel时,我不想在我的Excel中显示边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!