После seraching я пришел с этим
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=User.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.AllowSorting = false;
GridView1.Columns[14].Visible = false;
GridView1.Columns[15].Visible = false;
GridView1.Columns[16].Visible = false;
BindGird();
GridView1.HeaderRow.BackColor = Color.White;
foreach (TableCell cell in GridView1.HeaderRow.Cells)
{
cell.BackColor = GridView1.HeaderStyle.BackColor;
}
foreach (GridViewRow row in GridView1.Rows)
{
row.BackColor = Color.White;
foreach (TableCell cell in row.Cells)
{
if (row.RowIndex % 2 == 0)
{
cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
}
else
{
cell.BackColor = GridView1.RowStyle.BackColor;
}
cell.CssClass = "textmode";
}
}
GridView1.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
GridView1.Dispose();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
и ASPX изменения Принтлуны как
<%@ Page Title="" Language="C#" EnableEventValidation="false"%>
в VB я думаю, это выглядит, как этот
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.Clear
Response.Buffer = true
Response.AddHeader("content-disposition", "attachment;filename=User.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
Dim sw As StringWriter = New StringWriter
Dim hw As HtmlTextWriter = New HtmlTextWriter(sw)
GridView1.AllowPaging = false
GridView1.AllowSorting = false
GridView1.Columns(14).Visible = false
GridView1.Columns(15).Visible = false
GridView1.Columns(16).Visible = false
BindGird
GridView1.HeaderRow.BackColor = Color.White
For Each cell As TableCell In GridView1.HeaderRow.Cells
cell.BackColor = GridView1.HeaderStyle.BackColor
Next
For Each row As GridViewRow In GridView1.Rows
row.BackColor = Color.White
For Each cell As TableCell In row.Cells
If ((row.RowIndex Mod 2) _
= 0) Then
cell.BackColor = GridView1.AlternatingRowStyle.BackColor
Else
cell.BackColor = GridView1.RowStyle.BackColor
End If
cell.CssClass = "textmode"
Next
Next
GridView1.RenderControl(hw)
'style to format numbers to string
Dim style As String = "<style> .textmode { } </style>"
Response.Write(style)
Response.Output.Write(sw.ToString)
Response.Flush
Response.End
GridView1.Dispose
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
.aspx страница похожа на этот
<%@ Page Title="" Language="C#" EnableEventValidation="false"%>
Это не работает, так как они не являются именно первый столбец они построены в колонке я попытался это первый, но не работает – MohammadMMohammad
попытайтесь показать gvreseult.Columns (14) .Visible = true; после Response.End() и то же для других столбцов – amitesh
14,15,16 - это разные столбцы, которые я также не хочу экспортировать. Моя проблема заключается в том, что я не хочу показывать ссылки «Редактировать и удалять» в Excel, которые они отображаются в gridview, после включения AutoGenerateDeleteButton & AutoGenerateEditButton – MohammadMMohammad