comment manipuler un fichier excel depuis une dll qu'il appel lui meme
bonjour tout le monde
j'ai créé une dll que je veux appeler depuis un fichier excel pour manipuler ce dernier, mais jai mis le code suivant
Code:
excel.application app = new excel.application
mais apparemment ca créé un nouveau workbook
mais j'ai pas accés a mon workbook original qui fait appel a ma dll
comment dois je faire je sais que je dois me debarasser du <<new>>
merci
manipluer fichier excel par dll
bonjour,
voici un programme principal avec un classeur excel ,qui appelle une dll qui modifie le classeur:
-tu ajoute un bouton btnFichierExcel
-il faut faire ajouter une reference au projet manipExcel
Code:
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
|
'Programme WinAppExcel principal
Imports Microsoft.Office.Interop
Imports manipExcel
Public Class Form1
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
End Sub
Private Sub btnFichierExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFichierExcel.Click
Dim monFich As String = ""
OpenFileDialog1.Filter = "Fichier Excel(*.xls)|*.xls"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
monfich = OpenFileDialog1.FileName
If Len(monFich) = 0 Then
MessageBox.Show("entrer nom fichier svp...")
End If
Call Traitement(monfich)
End If
End Sub
Sub Traitement(ByVal nomfich As String)
Dim monAppExcel = New Excel.Application
Dim monClass As Excel.Workbook = monAppExcel.Workbooks.Open(nomfich)
Dim maFeuille As Excel.Worksheet = monClass.Worksheets(1)
monAppExcel.Visible = True
Dim objCalcul As dllDansExcel = New dllDansExcel
objCalcul.Calculs(maFeuille)
End Sub
End Class |
voici le projet bibliotheque manipExcel de classes de la DLL à creer:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
'Projet manipExcel qui contient la DLL qui modifie le classeur
Imports Microsoft.Office.Interop
Public Class dllDansExcel
Public Sub Calculs(ByVal maFeuile As Excel.Worksheet)
Dim rng1, rng2, rngResultat, titre As Excel.Range
rng1 = maFeuile.Cells(1, 2)
rng2 = maFeuile.Cells(2, 2)
rngResultat = maFeuile.Cells(3, 2)
titre = maFeuile.Cells(3, 1)
titre.Value = "Produit :"
rng1.Value = 15.25
rng2.Value = 45.27
rngResultat.Value = rng1.Value * rng2.Value
End Sub
End Class |
comme l'as dit aurel_le_ouf tu peux faire un tas de choses variees ,il faut dire ce que tu envisages exactement,pour etre bien oriente...
bon code...