Bonjour à tous,

Je sollicite votre aide concernant un probléme d'export vers excel d'un gridview ayant deux lignes de titres. La restitution dans Excel ne correspond pas à ce que j'ai dans le gridview à savoir qu'il y a une ligne de titre de vide et la derniére ligne e totalisation n'apparait pas.

Ci-dessous code présent dans le code behind pour ajouter la ligne de titre supplémentaire :

Private Sub GV_Total_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GV_Total.RowDataBound

If e.Row.RowType = DataControlRowType.Header Then

Dim table As Table = CType(e.Row.Parent, Table)

Dim row As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal)

Dim cell As TableCell = New TableCell()

cell.ColumnSpan = 1
cell.BackColor = Color.Transparent
cell.Text = "Titre"

cell.Style.Value = "font-weight:bold;"
row.Cells.Add(cell)
cell = New TableCell()

cell.ColumnSpan = 2
cell.HorizontalAlign = HorizontalAlign.Center
cell.Text = "PROSPECT"
cell.BackColor = Color.BlueViolet


cell.Style.Value = "font-weight:bold;"
row.Cells.Add(cell)
cell = New TableCell()

cell.ColumnSpan = 3
cell.HorizontalAlign = HorizontalAlign.Center
cell.Text = "STATUT EER"
cell.BackColor = Color.Blue

cell.Style.Value = "font-weight:bold;"
row.Cells.Add(cell)
cell = New TableCell()

cell.ColumnSpan = 7
cell.HorizontalAlign = HorizontalAlign.Center
cell.Text = "PHASE"
cell.BackColor = Color.DarkBlue

cell.Style.Value = "font-weight:bold;"
row.Cells.Add(cell)

e.Row.Cells(1).BackColor = Color.BlueViolet
e.Row.Cells(2).BackColor = Color.BlueViolet
e.Row.Cells(3).BackColor = Color.Blue
e.Row.Cells(4).BackColor = Color.Blue
e.Row.Cells(5).BackColor = Color.Blue
e.Row.Cells(6).BackColor = Color.DarkBlue
e.Row.Cells(7).BackColor = Color.Brown
e.Row.Cells(8).BackColor = Color.DarkBlue
e.Row.Cells(9).BackColor = Color.DarkBlue
e.Row.Cells(10).BackColor = Color.DarkBlue
e.Row.Cells(11).BackColor = Color.DarkBlue
e.Row.Cells(12).BackColor = Color.DarkBlue

table.Rows.AddAt(0, row)


End If
End Sub

ci-dessous code présent dans le code behind pour l'export vers Excel :

Protected Sub ImageButton_Export_Suivi_Total_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles ImageButton_Export_Suivi_Total.Click
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=fichierExcel.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim sr As StringWriter = New StringWriter
Dim HTW As HtmlTextWriter = New HtmlTextWriter(sr)
GV_Total.Controls(0).RenderControl(HTW)
Response.Write(sr.ToString())
Response.End()
End Sub

Merci d'avance pour votre aide