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 :

Afficher et modifier fichier excel dans un navigateur


Sujet :

ASP.NET

  1. #1
    Membre du Club Avatar de grand_prophete
    Inscrit en
    Avril 2005
    Messages
    85
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 85
    Points : 40
    Points
    40
    Par défaut Afficher et modifier fichier excel dans un navigateur
    Bonjour

    Voila, pour les besoins de mon travail, je veux pouvoir afficher un fichier excel hébergé sur un serveur dans un navigateur web et le modifier. Le but est que n'importe qui puisse y acceder depuis une URL et rajouter ses informations. Cela fait longtemps que je n'ai pas touché a la prog, je suis sous visual studio 2008 trial version.
    Merci d'avance pour votre aide

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    116
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 116
    Points : 149
    Points
    149
    Par défaut
    En gros tu veux un composant asp.net pour pouvoir faire l'équivalent de google spreadsheet ?

    Essaye avec un gridview (ou l'équivalent webcontrols) et avec les events tu dois pouvoir modifier les champs.

    Il te faudras la librairie Microsoft.Interop.Excel afin de charger le fichier excel

  3. #3
    Responsable .NET

    Avatar de Hinault Romaric
    Homme Profil pro
    Consultant
    Inscrit en
    Janvier 2007
    Messages
    4 570
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 4 570
    Points : 252 372
    Points
    252 372
    Billets dans le blog
    121
    Par défaut
    Lie tes données et charge les dans un GridView après les modifications tu écrase l'ancien fichier.

    @++

  4. #4
    Membre du Club Avatar de grand_prophete
    Inscrit en
    Avril 2005
    Messages
    85
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 85
    Points : 40
    Points
    40
    Par défaut
    Voici le bout de code qui me sert a lire et ouvrir un fichier excel, et non pas l'afficher dans un navigateur. Je voudrais utiliser le grid view comme vous me l'avez conseillé. Comment est ce que je dois m'y prendre pour charger les données du fichier excel dans ce grid view (a partir du moment ou j'arrive sur datasource) ? Merci

    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
     
      Dim appxls As Microsoft.Office.Interop.Excel.Application
            Dim book As Microsoft.Office.Interop.Excel.Workbook
            Dim excelfile As String
            Dim OpenFichierExcel As New System.Windows.Forms.OpenFileDialog()
     
     
            OpenFichierExcel.FileName = "InventairesBytel_thomas_manu_steph.xls"
            OpenFichierExcel.InitialDirectory = "C:\"
            OpenFichierExcel.Filter = "Fichiers Excel (*.xls)|*.xls"
            OpenFichierExcel.FilterIndex = 1
            OpenFichierExcel.Title = "Ouvrir un fichier Excel"
            OpenFichierExcel.RestoreDirectory = True
     
            appxls = New Microsoft.Office.Interop.Excel.Application
            appxls.Visible = True
            excelfile = OpenFichierExcel.FileName
            book = appxls.Workbooks.Open(excelfile)

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    116
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 116
    Points : 149
    Points
    149
    Par défaut
    bah avec une boucle ?

    J'ai pas du comprendre la question...

  6. #6
    Membre du Club Avatar de grand_prophete
    Inscrit en
    Avril 2005
    Messages
    85
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 85
    Points : 40
    Points
    40
    Par défaut
    En fait, lorsque je rajoute un gridview sur mon interface, je dois lui indiquer le Data Source pour qu'il lise et affiche les donnees de mon fichier excel (enfin je pense que c'est ca). A partir de la je ne sais pas quoi faire.

  7. #7
    Responsable .NET

    Avatar de Hinault Romaric
    Homme Profil pro
    Consultant
    Inscrit en
    Janvier 2007
    Messages
    4 570
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 4 570
    Points : 252 372
    Points
    252 372
    Billets dans le blog
    121

  8. #8
    Responsable .NET

    Avatar de Hinault Romaric
    Homme Profil pro
    Consultant
    Inscrit en
    Janvier 2007
    Messages
    4 570
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 4 570
    Points : 252 372
    Points
    252 372
    Billets dans le blog
    121
    Par défaut
    Faut adapter le code a ton cas. il y'a certaine données qui doivent être modifier a l'instar par exemple du chemin du fichier .xls dans la chaine de connexion et le nom de la feuille dans la requête. Sinon poste ton code pour que je puisse voir ou ça coince.

    @++

  9. #9
    Membre du Club Avatar de grand_prophete
    Inscrit en
    Avril 2005
    Messages
    85
    Détails du profil
    Informations forums :
    Inscription : Avril 2005
    Messages : 85
    Points : 40
    Points
    40
    Par défaut
    En fait j'ai changé de strategie depuis vu que ca me paraissait trop compliqué la gestion des sources sql etc..ducoup j'ai juste mis un bouton pour charger le fichier excel, et un autre pour l'uploader sur le serveur. Mais j'ai des soucis quand je veux le tester en prod.

    Voici l'erreur

    Server Error in '/inventaire' Application.
    --------------------------------------------------------------------------------

    Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Runtime.InteropServices.COMException: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))

    Source Error:

    The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

    1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

    <%@ Page Language="C#" Debug="true" %>

    or:

    2) Add the following section to the configuration file of your application:

    <configuration>
    <system.web>
    <compilation debug="true"/>
    </system.web>
    </configuration>

    Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

    Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

    Stack Trace:


    [COMException (0x80028018): Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))]
    Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) +0
    _Default.Button1_Click(Object sender, EventArgs e) +177
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +107
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +111
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3436



    et le code

    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
     
     
    Imports Microsoft.Office.Interop.Excel
    Imports System.Windows.Forms.OpenFileDialog
    Imports System.Windows.Forms
    Partial Class _Default
        Inherits System.Web.UI.Page
     
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim appxls As Microsoft.Office.Interop.Excel.Application
            Dim book As Microsoft.Office.Interop.Excel.Workbook
            Dim excelfile As String
            Dim OpenFichierExcel As New System.Windows.Forms.OpenFileDialog()
     
            'configuation de l'openfiledialogue du fichier excel
            OpenFichierExcel.FileName = "InventairesBytel_thomas_manu_steph.xls"
            OpenFichierExcel.InitialDirectory = "C:\Inetpub\wwwroot\inventaire\"
            OpenFichierExcel.Filter = "Fichiers Excel (*.xls)|*.xls"
            OpenFichierExcel.FilterIndex = 1
            OpenFichierExcel.Title = "Ouvrir un fichier Excel"
            OpenFichierExcel.RestoreDirectory = True
     
            ' Dim result As DialogResult = OpenFichierExcel.ShowDialog() 'affiche la boite
     
            ' If (result = DialogResult.OK) Then
            'ouverture de l'application et du classeur
            appxls = New Microsoft.Office.Interop.Excel.Application
            appxls.Visible = True
            excelfile = OpenFichierExcel.FileName
            book = appxls.Workbooks.Open(excelfile)
            'Else
            'Exit Sub
            'End If
        End Sub
     
        Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
            If FileUpload1.HasFile Then
                Try
                    FileUpload1.SaveAs("C:\Inetpub\wwwroot\inventaire\" & _
                       FileUpload1.FileName)
                    Label1.Text = "File name: " & _
                       FileUpload1.PostedFile.FileName & "<br>" & _
                       "File Size: " & _
                       FileUpload1.PostedFile.ContentLength & " kb<br>" & _
                       "Content type: " & _
                       FileUpload1.PostedFile.ContentType
                Catch ex As Exception
                    Label1.Text = "ERROR: " & ex.Message.ToString()
                End Try
            Else
                Label1.Text = "You have not specified a file."
            End If
     
        End Sub
    End Class

Discussions similaires

  1. Modifier fichier Excel dans l'application
    Par Spellbinder dans le forum VB.NET
    Réponses: 3
    Dernier message: 13/02/2011, 23h01
  2. ouvrir un fichier excel dans le navigateur web
    Par cyclopsnet dans le forum Entrée/Sortie
    Réponses: 2
    Dernier message: 18/08/2009, 12h35
  3. [Excel] Afficher plusieurs fichiers excel dans un seul fichier
    Par naru40001 dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 07/01/2009, 14h50
  4. Réponses: 4
    Dernier message: 11/07/2007, 18h40
  5. ne pas ouvir un fichier (excel) dans le navigateur
    Par guns17 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 18/01/2007, 15h09

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