impression sous condition fichier excel
salut
je bloque volontairement l'impression de mes fichier excel de la façon suivante (en dur dans le fichier excel pour eviter quon ouvre le fichier sans passé par mon programme de vérification des cellule ...) :
Code:
1 2 3
| Private Sub Workbook_BeforePrint(Cancel As Boolean)
cancel = true
End Sub |
mon programme en vb.net verifie que certaines cellules sont bien remplies puis doit imprimer le fichier .
Le souci est que je ne sais pas comment remettre l'option cancel = False avec une commande vb.net
du genre :
j'ouvre fichier excel OK
je check mes cellule OK
j'autorise l'impression ????????
j'imprime OK
et je re-interdit l'impression ?????
Merci d'avance pour votre aide
activer print ,desactiver print
bonjour gyver4000
Tout n'est pas disponible dans l'api par exemple l'invere de l'evenement BeforePrint c.à.d AfterPrint
Mais tu peux mettre un boolean de telle maniere à desactiver l'evenement juste apres impression.
code:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
Imports OXL = Microsoft.Office.Interop.Excel
Public Class Form1
Private excelApp As OXL.Application
Private WithEvents excelWbk As OXL.Workbook
Private WithEvents excelSheet As OXL.Worksheet
Dim activerImpression As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAfficheExcel.Click
Dim chFichier As String = ""
Dim dlgOpen As OpenFileDialog = New OpenFileDialog
If dlgOpen.ShowDialog + Windows.Forms.DialogResult.OK Then
chFichier = dlgOpen.FileName
If Len(chFichier) = 0 Then Return
'nota bene
activerImpression = False
excelApp = New OXL.Application
excelWbk = excelApp.Workbooks.Open(chFichier)
excelSheet = excelWbk.Worksheets(2)
excelApp.Visible = True
End If
End Sub
Private Sub excelWBK_BeforePrint(ByRef Cancel As Boolean) Handles excelWBK.BeforePrint
If Not activerImpression Then
Cancel = True
Else
Cancel = False
End If
End Sub
Private Sub btnImprime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImprime.Click
If excelWbk IsNot Nothing Then
If excelWbk.Worksheets(2) IsNot Nothing Then
activerImpression = True
excelSheet = excelWbk.Worksheets(1)
excelSheet.PrintOut(1, 4, 1, True, , , , )
End If
End If
activerImpression = False
End Sub
Private Sub btnQuitter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuitter.Click
excelSheet = Nothing
excelWbk = Nothing
excelApp.Quit()
excelApp = Nothing
End Sub
End Class |
bon code.....