IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

exporter grid view vers excel


Sujet :

ASP.NET

  1. #1
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut exporter grid view vers excel
    Bonjour, je veux exporter mon grid vers excel :

    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>
    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
        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();
            }
        }
    Le programme s"execute bien sans aucune erreur mais le fichier ne s'affiche pas meme si le telechargement des fichiers est activee

    des idees ?

  2. #2
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut
    Le probleme est au niveau du positionnemenet du boutton pas dans le code behind parce que le code marche sur une autre page de test

    J ai fait sortir le bouton du tabcontainer et ca ne marche toujours pas

  3. #3
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut
    j'AI Ajouté un trigger a mon premier update panel mais rien ne marche

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    ....
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
                                                <SortedDescendingHeaderStyle BackColor="#4870BE" />
                                            </asp:GridView>
                                        </div>
                                        <br>
                                        <div style="text-align: right">
                                            <asp:Button ID="AllExporter" Text="Exporter le tableau" CssClass="button" runat="server"
                                                OnClick="AllExporter_Click" />
                                        </div>
                                    </ContentTemplate>
                                                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="AllExporter"
    j'ai vraiment besoin d'aide

Discussions similaires

  1. [Débutant] exporter liste view vers fichier excel
    Par Msysteme dans le forum C#
    Réponses: 8
    Dernier message: 23/09/2012, 02h13
  2. Exporter une view vers un fichier excel.
    Par pauvremen dans le forum C#
    Réponses: 3
    Dernier message: 15/08/2008, 20h27
  3. Export données MsFlexGrid vers Excel VB6.0
    Par elabbassi dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 16/09/2005, 14h18
  4. Export de données vers Excel
    Par psykot63 dans le forum Access
    Réponses: 2
    Dernier message: 03/01/2005, 12h04
  5. export de requete vers excel(pb de mise en forme)
    Par syl221 dans le forum Access
    Réponses: 13
    Dernier message: 20/10/2004, 15h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo