Bonjour, je veux exporter mon grid vers excel :
mon grid s'affiche bien
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 <asp:UpdatePanel runat="server"> <ContentTemplate> <asp:HiddenField ID="HiddenFiltre" runat="server" /> <asp:TabContainer ID="TabContainer" runat="server" CssClass="fancy fancy-green"> <asp:TabPanel ID="Tabstations" runat="server" HeaderText="Liste des Stations"> <ContentTemplate> <asp:UpdatePanel ID="upGridliste" runat="server"> <ContentTemplate> <h3 class="blocksubhead"> Stations filtrées :</h3> <div> <br /> <asp:GridView ID="listeStations" runat="server" AutoGenerateColumns="False" OnRowCommand="listeStations_RowCommand" AllowPaging="True" ForeColor="#333333" BorderColor="#E6E6E6" GridLines="Horizontal" Width="940px" Style="font-size: 9pt; color: black; font-family: Arial" PageSize="20" OnPageIndexChanging="listeStations_PageIndexChanging"> <AlternatingRowStyle BackColor="White" /> <Columns> ..... </Columns> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#0066FF" Font-Bold="True" ForeColor="#e9e9e9" /> <HeaderStyle BackColor="#0066FF" Font-Bold="false" ForeColor="#e9e9e9" Font-Size="9" Height="30px" HorizontalAlign="Left" /> <PagerStyle BackColor="#0066FF" ForeColor="#e9e9e9" HorizontalAlign="Left" Height="20px" /> <RowStyle BackColor="#f3f3f3" Font-Size="9" Height="25px" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="false" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> </asp:GridView> </div> <br> </ContentTemplate> </asp:UpdatePanel> <div style="text-align: right"> <asp:Button ID="AllExporter" Text="Exporter le tableau" CssClass="button" runat="server" OnClick="AllExporter_Click" /> </div> </ContentTemplate> </asp:TabPanel> <asp:TabPanel ID="TabInfos" runat="server" HeaderText="Detail"> .... </asp:TabPanel> <asp:TabPanel ID="TabEchange" runat="server" HeaderText="Correspondances"> <ContentTemplate> .... </ContentTemplate> </asp:TabPanel> </asp:TabContainer> </ContentTemplate> </asp:UpdatePanel>
Le programme s"execute bien sans aucune erreur mais le fichier ne s'affiche pas meme si le telechargement des fichiers est activee
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public override void VerifyRenderingInServerForm(Control control) { /* Verifies that the control is rendered */ } protected void AllExporter_Click(object sender, EventArgs e) { //string nmFile = "Export_" + System.DateTime.Now.Day + "_" + System.DateTime.Now.Month + "_" + System.DateTime.Now.Year + ".xls"; Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); //To Export all pages //listeStations.AllowPaging = false; //this.BindGrid(); listeStations.HeaderRow.BackColor = Color.White; foreach (TableCell cell in listeStations.HeaderRow.Cells) { cell.BackColor = listeStations.HeaderStyle.BackColor; } foreach (GridViewRow row in listeStations.Rows) { row.BackColor = Color.White; foreach (TableCell cell in row.Cells) { if (row.RowIndex % 2 == 0) { cell.BackColor = listeStations.AlternatingRowStyle.BackColor; } else { cell.BackColor = listeStations.RowStyle.BackColor; } cell.CssClass = "textmode"; } } listeStations.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(); } }
des idees ?
Partager