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

VB.NET Discussion :

Choix de type de sortie d'impression


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2015
    Messages
    52
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2015
    Messages : 52
    Par défaut Choix de type de sortie d'impression
    Bonjour à tous,j'aimerais juste savoir comment faire pour imprimer un formulaire que j'ai crée en un fichier type excel.
    J'utilisais habituellement l'outil printform mais je sais pas si avec ce même outil,je peux imprimer le formulaire vers excel.Si oui,comment faire?Sinon, comment puis-je procéder?

  2. #2
    Membre très actif
    Profil pro
    Inscrit en
    Avril 2013
    Messages
    267
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2013
    Messages : 267
    Par défaut
    Bonjour,

    Voici un exemple ce que vous pouvez faire :
    Nom : excel.jpg
Affichages : 435
Taille : 131,5 Ko

    voici mon codes :
    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
    Public Class Form1
     
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim LIRE As String
            LIRE = Application.StartupPath & "\Exemple.xls"
            IO.File.WriteAllBytes(LIRE, My.Resources.Exemple)
            DataGridView1.Rows.Clear()
            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim dataSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & LIRE & ";Extended Properties=Excel 8.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [BDD$]", MyConnection)
            dataSet = New System.Data.DataSet
            MyCommand.Fill(dataSet)
            DataGridView1.DataSource = dataSet.Tables(0)
            DataGridView1.Columns(0).Width = 100
            DataGridView1.Columns(1).Width = 100
            DataGridView1.Columns(2).Width = 100
            DataGridView1.Columns(3).Width = 100
            DataGridView1.Columns(4).Width = 100
            DataGridView1.Columns(5).Width = 100
            DataGridView1.Columns(6).Width = 100
            DataGridView1.Columns(7).Width = 100
            DataGridView1.Columns(8).Width = 100
        End Sub
     
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            PrintDocument1.DefaultPageSettings.Landscape = True
            Dim margins As New Printing.Margins(50, 100, 100, 100)
            PrintDocument1.DefaultPageSettings.Margins = margins
            PrintPreviewDialog1.PrintPreviewControl.Zoom = 1
            PrintPreviewDialog1.Document = PrintDocument1
            PrintPreviewDialog1.Size = New System.Drawing.Size(1000, 200)
            AddHandler PrintDocument1.PrintPage, AddressOf PrintDocument1_PrintPage
            PrintPreviewDialog1.ShowDialog()
        End Sub
     
        Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
             Dim dataGridViewImage As Bitmap = New Bitmap(Me.dataGridView1.Width, Me.dataGridView1.Height)
            DataGridView1.DrawToBitmap(dataGridViewImage, New Rectangle(0, 0, Me.DataGridView1.Width, Me.DataGridView1.Height))
            e.Graphics.DrawImage(dataGridViewImage, 0, 0)
        End Sub
     
        Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
            PrintDocument1.DefaultPageSettings.Landscape = True
            PrintDocument1.Print()
        End Sub
    End Class
    cordialement,

  3. #3
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2015
    Messages
    52
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2015
    Messages : 52
    Par défaut
    Déjà merci pour l'aide que tu m'apportes.
    Je rencontre un problème quant à la lecture du fichier,le message d'erreur suivant s'affichent: "Cannot clear this list."
    Et en ce qui concerne l'impression à proprement parlé,ça passe,mais c'est comme ce que je faisais avant.Il est imprimer au format pdf.
    En fait,ce que je souhaite (au cas où je n'ai pas été bien explicite), c'est que la partie à imprimer (mon formulaire dans mon cas) soit imprimé au format excel.
    Merci d'avance pour ta réponse.

  4. #4
    Membre très actif
    Profil pro
    Inscrit en
    Avril 2013
    Messages
    267
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2013
    Messages : 267
    Par défaut
    Bonjour,

    Je rencontre un problème quant à la lecture du fichier,le message d'erreur suivant s'affichent: "Cannot clear this list."

    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
    Dim LIRE As String = "'Tu ajoute le répertoire du fichier XLS => ( c:/exemple.xls)"
    DataGridView1.Rows.Clear()
            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim dataSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & LIRE & ";Extended Properties=Excel 8.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [BDD$]", MyConnection)
            dataSet = New System.Data.DataSet
            MyCommand.Fill(dataSet)
            DataGridView1.DataSource = dataSet.Tables(0)
            DataGridView1.Columns(0).Width = 100 '
            DataGridView1.Columns(1).Width = 100 '
            DataGridView1.Columns(2).Width = 100 '
            DataGridView1.Columns(3).Width = 100 '=> nombre de colonne dans ton fichier XLS
            DataGridView1.Columns(4).Width = 100 '
            DataGridView1.Columns(5).Width = 100 '
            DataGridView1.Columns(6).Width = 100 '
            DataGridView1.Columns(7).Width = 100 '
            DataGridView1.Columns(8).Width = 100
    j'ai pas bien compris ce que vous voulez dire? Es ce que vous voulez dire que vous avez un fichier PDF est l'imprimer en format Excel?

  5. #5
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2015
    Messages
    52
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2015
    Messages : 52
    Par défaut Imprimer vers excel
    Bonsoir!
    Non,je reconnais ne pas avoir été assez clair au début,et je m'en excuse.
    En fait, je développe un programme et j'utilise mysql workbrench comme base de donnée.
    Avec un tablelayoutpanel, j'ai crée un tableau dans lequel les informations entrées (à l'aide de textbox) sont insérées dans une des tables de ma base de donnée (soit par exemple la table x).
    J'ai utilisé ensuite un datagridview pour afficher les informations de la table x sur un windows form, et quand je clique sur une donnée,toutes les informations sont affichées dans des textbox prévus à cet effet. Puis, avec un bouton,j'arrive à imprimer ces informations dans un fichier pdf créée au moment de l'impression.Voici le code que j'utilise pour ce faire:

    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
     
    Dim myConnexion As MySqlConnection
        Dim myCommand As MySqlCommand
        Dim dbDataset As New DataTable
     
    Private Sub Etat_client_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     
    myConnexion = New MySqlConnection
            myConnexion.ConnectionString = "server = localhost; userid = root; password = abc; database = ok"
            Dim sda As New MySqlDataAdapter
            Dim bsource As New BindingSource
     
            Try
                myConnexion.Open()
                Dim query As String
                query = "select date,denomination,numero_facture,cc from ok.a"
                myCommand = New MySqlCommand(query, myConnexion)
                sda.SelectCommand = myCommand
                sda.Fill(dbDataset)
                bsource.DataSource = dbDataset
                DataGridView1.DataSource = bsource
                sda.Update(dbDataset)
     
                myConnexion.Close()
     
            Catch ex As MySqlException
                MessageBox.Show(ex.Message)
            Finally
                myConnexion.Dispose()
            End Try
     
    End Sub
     
    Private Sub BT_IMPRIMER_Click(sender As Object, e As EventArgs) Handles BT_IMPRIMER.Click
     
     
     
    With PrintForm1.PrinterSettings.DefaultPageSettings.Margins
                        .Top = 10
                        .Left = 10
                        .Bottom = 100
                        .Right = 10
                    End With
                    PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
                    PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
     
     
    End Sub
     
    Private Sub DataGridView1_CellContentClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
            If e.RowIndex >= 0 Then
                Dim Row As DataGridViewRow
                Row = Me.DataGridView1.Rows(e.RowIndex)
     
                MTDATE.Text = Row.Cells("date").Value.ToString
                TXT_DENOMINATION.Text = Row.Cells("denomination").Value.ToString
                TXTFACTURE.Text = Row.Cells("numero_facture").Value.ToString
                TXTNUMEROCC.Text = Row.Cells("cc").Value.ToString
    End If
        End Sub
    Ce code marche très bien,et les informations sont imprimer dans une feuille au format pdf. Mais je veux à présent imprimer les informations dans un fichier excel qui sera créée au moment de l'impression.

  6. #6
    Inactif  

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2012
    Messages
    4 903
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2012
    Messages : 4 903
    Billets dans le blog
    36
    Par défaut
    Bonjour,

    Trouvé avec le moteur de recherche du site:

    http://www.developpez.net/forums/d76...ew-vers-excel/

    Il y a aussi quelques liens à partir de cette page:

    http://www.codeproject.com/search.as...sbo=kw&x=8&y=9

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [MySQL] Choix du type de champs
    Par hbellahc dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 03/09/2006, 21h40
  2. Mysql : choix des types pour les champs entre :
    Par Thierry8 dans le forum Administration
    Réponses: 3
    Dernier message: 14/06/2006, 08h22
  3. [architecture] Choix du type de pile
    Par Neitsa dans le forum Algorithmes et structures de données
    Réponses: 3
    Dernier message: 29/11/2005, 10h04
  4. Problème de choix de page lors de l'impression
    Par Olaf MENJI dans le forum Windows
    Réponses: 2
    Dernier message: 22/11/2005, 10h51
  5. choix des types
    Par cali dans le forum Langage SQL
    Réponses: 3
    Dernier message: 10/08/2004, 13h16

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