当我使用网格导出为ex​​cel时,我不想在我的Excel中显示边框 [英] I dont want to show borders in my excel when i use grid for export to excel

查看:76
本文介绍了当我使用网格导出为ex​​cel时,我不想在我的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);


这篇关于当我使用网格导出为ex​​cel时,我不想在我的Excel中显示边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆