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

Windows Forms Discussion :

[vb2005-E]Pb d'impression et d'exportation sous excel


Sujet :

Windows Forms

  1. #1
    Futur Membre du Club
    Inscrit en
    Mai 2006
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 11
    Points : 7
    Points
    7
    Par défaut [vb2005-E]Pb d'impression et d'exportation sous excel
    Bonjour à tous
    ca fait qq temps que je lisais votre forum et site sans poser de question, mais voila, étant débutant, je coince sur deux sujets :

    1 : voila, à force de lire, lire et encore lire, j'ai réussi à imprimer mon datagridview grace au site de M PLASSERRE, mais voila, mon impression comporte 2 pbs
    - la zone d'impression doit faire 4cm² au lieu de prendre une page entiere
    Je pense que je dois parametrer qq chose, mais je ne vois pas du tout quoi
    j'utilise l'impression par defaut, mon datagrid contient de nombreuses lignes et colonnes
    - ensuite, mon impression ne comporte pas toutes les lignes, elle prends les 16 ou 18 premieres lignes, genere une seule page, c'est tout
    voila mon code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    Private Sub ImprimerToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImprimerToolStripButton.Click
            PrintDocument.Print()
        End Sub
     
     
        Private Sub PrintDocument_PrintPage(ByVal sender As System.Object, _
       ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
       PrintDocument.PrintPage
            Dim myPaintArgs As New PaintEventArgs(e.Graphics, New Rectangle(New _
               Point(0, 0), Me.Size))
            Me.InvokePaint(DmesActivesDataGridView, myPaintArgs)
        End Sub
    mon deuxieme pb, arriver à exporter mon datagrid vers excel,
    comme precedemment, à force de recherche , j'ai reussi l'export de ma base access, mais pas de mon datagrid, je pense qu'une simple modif du code doit suffir, mais la encore je seche
    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
     
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim cnt As New ADODB.Connection
            Dim rst As New ADODB.Recordset
     
            Dim xlApp As Object
            Dim xlWb As Object
            Dim xlWs As Object
     
     
            Dim recArray As Object
     
            Dim strDB As String
            Dim fldCount As Integer
            Dim recCount As Long
            Dim iCol As Integer
            Dim iRow As Integer
     
            ' Set the string to the path of your Northwind database
            strDB = "bd1.mdb"
     
            ' Open connection to the database
            cnt.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=" & strDB & ";")
     
            ' Open recordset based on Orders table
            rst.Open("Select * From DmesActives", cnt)
     
            ' Create an instance of Excel and add a workbook
            xlApp = CreateObject("Excel.Application")
            xlWb = xlApp.Workbooks.Add
            xlWs = xlWb.Worksheets("Feuil1")
     
            ' Display Excel and give user control of Excel's lifetime
            xlApp.Visible = True
            xlApp.UserControl = True
     
            ' Copy field names to the first row of the worksheet
            fldCount = rst.Fields.Count
            For iCol = 1 To fldCount
                xlWs.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name
            Next
     
            ' Check version of Excel
            If Val(Mid(xlApp.Version, 1, InStr(1, xlApp.Version, ".") - 1)) > 8 Then
                'EXCEL 2000 or 2002: Use CopyFromRecordset
     
                ' Copy the recordset to the worksheet, starting in cell A2
                xlWs.Cells(2, 1).CopyFromRecordset(rst)
                'Note: CopyFromRecordset will fail if the recordset
                'contains an OLE object field or array data such
                'as hierarchical recordsets
     
            Else
                'EXCEL 97 or earlier: Use GetRows then copy array to Excel
     
                ' Copy recordset to an array
                recArray = rst.GetRows
                'Note: GetRows returns a 0-based array where the first
                'dimension contains fields and the second dimension
                'contains records. We will transpose this array so that
                'the first dimension contains records, allowing the
                'data to appears properly when copied to Excel
     
                ' Determine number of records
     
                recCount = UBound(recArray, 2) + 1 '+ 1 since 0-based array
     
     
                ' Check the array for contents that are not valid when
                ' copying the array to an Excel worksheet
                For iCol = 0 To fldCount - 1
                    For iRow = 0 To recCount - 1
                        ' Take care of Date fields
                        If IsDate(recArray(iCol, iRow)) Then
                            recArray(iCol, iRow) = Format(recArray(iCol, iRow))
                            ' Take care of OLE object fields or array fields
                        ElseIf IsArray(recArray(iCol, iRow)) Then
                            recArray(iCol, iRow) = "Array Field"
                        End If
                    Next iRow 'next record
                Next iCol 'next field
     
                ' Transpose and Copy the array to the worksheet,
                ' starting in cell A2
                xlWs.Cells(2, 1).Resize(recCount, fldCount).Value = _
                    TransposeDim(recArray)
            End If
     
            ' Auto-fit the column widths and row heights
            xlApp.Selection.CurrentRegion.Columns.AutoFit()
            xlApp.Selection.CurrentRegion.Rows.AutoFit()
     
            ' Close ADO objects
            rst.Close()
            cnt.Close()
            rst = Nothing
            cnt = Nothing
     
            ' Release Excel references
            xlWs = Nothing
            xlWb = Nothing
     
            xlApp = Nothing
     
        End Sub
    merci à son auteur, je sais plus ou j'ai pris ca

    Merci de votre aide

  2. #2
    Futur Membre du Club
    Inscrit en
    Mai 2006
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Mai 2006
    Messages : 11
    Points : 7
    Points
    7
    Par défaut
    Re-

    désolé de reposter, mais je n'ai toujours pas trouvé

    si qq'un connait un site spécialisé sur le vb 2005 E, ça serait cool

    Merci

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2006
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 21
    Points : 17
    Points
    17
    Par défaut
    As tu trouvé car j'ai le meme problème que toi.
    On peut imprimer juste la Form mais lorsque mon datagridview à plusieurs lignes.
    Eh ben,je suis bai... car on peut pas savoir le nombre de page

    Merci

Discussions similaires

  1. export sous Excel
    Par lexou27 dans le forum Documents
    Réponses: 1
    Dernier message: 09/08/2006, 15h02
  2. Réponses: 6
    Dernier message: 26/07/2006, 16h36
  3. [vb2005-E]Export sous excel
    Par moriss dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 23/05/2006, 08h59
  4. export sous Excel
    Par gohu13 dans le forum Access
    Réponses: 3
    Dernier message: 25/11/2005, 14h27
  5. Export sous excel d'une zone déroulante
    Par jaja63 dans le forum Access
    Réponses: 3
    Dernier message: 27/09/2005, 16h18

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