High-Tech
Santé-Médecine
Droit-Finances
CodeS-SourceS
Inscription
Plan
Connexion
Rechercher un code, un tuto, une réponse
Accueil
Forum
Tutoriels
Codes Sources
Snippets
Top membres
Tous les langages
Delphi / Pascal
Java
Python
SQL
RegEx
Flash
ASM
IRC
Graphisme
PDA
ColdFusion
Foxpro
Flex
Visual Basic / VB.NET
Forum
Tutoriels
Codes Sources
Snippets
Top membres
PHP
Forum
Tutoriels
Codes Sources
Snippets
Top membres
C/C++/C++.NET
Forum
Tutoriels
Codes Sources
Snippets
Top membres
Javascript
Forum
Tutoriels
Codes Sources
Snippets
Top membres
C#/.NET
Forum
Tutoriels
Codes Sources
Snippets
Top membres
ASP/ASP.NET
Forum
Tutoriels
Codes Sources
Snippets
Top membres
Accueil
Connexion
Déposer un code
Code
Recherche
Haut
Forum
Visual Basic
VB.NET
Sujet Précédent
Sujet Suivant
Transformer un datagrid en un document pdf
beet2che
Messages postés
84
Date d'inscription
samedi 17 mars 2007
Statut
Membre
Dernière intervention
14 avril 2009
- 12 oct. 2008 à 10:52
gillardg
Messages postés
3275
Date d'inscription
jeudi 3 avril 2008
Statut
Membre
Dernière intervention
14 septembre 2014
-
12 oct. 2008 à 18:29
Bonjour
en fait je voulais savoir comment transformer un datagrid en document pdf
merci
cordialement
Afficher la suite
A voir également:
Visual basic 2008 pdf
Visual basic 2005
-
Conseils pratiques -Visual Basic / VB.NET
If visual basic
-
Conseils pratiques -Visual Basic / VB.NET
Visual basic ide
✓
-
Forum Visual Basic
Alphabet arabe pdf
-
Forum PHP
Visual basic commentaire
✓
-
Forum VB.NET
3 réponses
Réponse 1 / 3
gillardg
Messages postés
3275
Date d'inscription
jeudi 3 avril 2008
Statut
Membre
Dernière intervention
14 septembre 2014
2
12 oct. 2008 à 15:50
en fichier excel c'est pas bon??
Bonjour chez vous !
Réponse 2 / 3
beet2che
Messages postés
84
Date d'inscription
samedi 17 mars 2007
Statut
Membre
Dernière intervention
14 avril 2009
12 oct. 2008 à 18:20
oui pourquoi ça m'arrange
merci
Réponse 3 / 3
gillardg
Messages postés
3275
Date d'inscription
jeudi 3 avril 2008
Statut
Membre
Dernière intervention
14 septembre 2014
2
12 oct. 2008 à 18:29
' * Le code permet d'exporter le contenu d'une datagrdiview vers un fichier excel
'**
Imports
Microsoft.VisualBasic
Imports
System
Imports
System.Collections.Generic
Imports
System.ComponentModel
Imports
System.Data
Imports
System.Text
Imports
System.Windows.Forms
Imports
System.Reflection
'''
<summary>
''' Dim ex As New ExportXls.now
''' ex.Export(datagv)
''' ex = Nothing
'''
</summary>
'''
<remarks></remarks>
Public
Class
now
Private
oXL
As
Microsoft.Office.Interop.Excel.Application
Private
oWB
As
Microsoft.Office.Interop.Excel._Workbook
Private
oSheet
As
Microsoft.Office.Interop.Excel._Worksheet
Private
oRng
As
Microsoft.Office.Interop.Excel.Range
Private
M
As
Object
= System.Reflection.Missing.Value#
Region
"Enregistrer le fichier Excel sous"
Public
Sub
SaveAs(
ByVal
sNameFichier
As
String
)
Try
oWB.SaveAs(sNameFichier, M, M, M, M, M, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, M, M, M, M, M)
Catch
e
As
ExceptionMessageBox.Show(e.Message)
End
Try
End
Sub
#
End
Region
Public
Function
Export(
ByRef
dtgv
As
DataGridView)
Dim
z
As
Int32 = 1
Dim
f
As
New
Formf.Width = 200
f.Height = 50
f.FormBorderStyle = FormBorderStyle.None
Dim
pgb
As
New
ProgressBarpgb.Parent = f
pgb.Dock = DockStyle.Fill
pgb.Style = ProgressBarStyle.Marquee
f.Show()
pgb.Value = pgb.Value + z
Dim
savefd1
As
New
SaveFileDialog
With
savefd1.AddExtension =
True
.DefaultExt =
".xlsx"
.CheckPathExists =
True
.DereferenceLinks =
True
.Filter =
"Excell 2007(*.xlsx)|*.xlsx"
.OverwritePrompt =
True
.ShowHelp =
True
.SupportMultiDottedExtensions =
True
.Title =
"Save as Excell 2007 file"
.ValidateNames =
True
End
With
Try
'Start Excel and get Application object.
oXL =
New
Microsoft.Office.Interop.Excel.Application()oXL.Visible =
False
pgb.Value = pgb.Value + z
'Get a new workbook.
oWB =
CType
(oXL.Workbooks.Add(System.Reflection.Missing.Value), Microsoft.Office.Interop.Excel._Workbook)oSheet =
CType
(oWB.ActiveSheet, Microsoft.Office.Interop.Excel._Worksheet)pgb.Value = pgb.Value + z
' Copier les noms des colonnes
Dim
i
As
Integer
= 0
For
Each
ch
As
DataGridViewColumn
In
dtgv.ColumnsoRng = oSheet.Range(Convert.ToChar(65 + i).ToString() &
"1"
, Missing.Value)oSheet.Cells(1, i + 1) = ch.Name.Trim()
oRng.Interior.ColorIndex = Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexAutomatic
oRng.Font.Bold =
True
oRng.BorderAround(Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin, Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value)
oRng.EntireColumn.AutoFit()
pgb.Value = pgb.Value + z
i += 1
Next
ch
' Copier toutes les cellules du datagridview
' j=2 on commence à la 2eme ligne dans le fichier excel
Dim
j
As
Integer
= 2
For
Each
uneLigne
As
DataGridViewRow
In
dtgv.Rowspgb.Value = pgb.Value + z
i = 1
' si i=1 alors 65-1+1 donne 65<=>A et ainsi on aura la lettre de la colonne puis on juxtapose le numero de la ligne
For
Each
uneColonne
As
DataGridViewColumn
In
dtgv.ColumnsoRng = oSheet.Range(Convert.ToChar(65 + i - 1).ToString() & j.ToString(), Missing.Value)
oSheet.Cells(j, i) = uneLigne.Cells(uneColonne.Name).Value.ToString().Trim()
oRng.BorderAround(Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin, Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value)
oRng.EntireColumn.AutoFit()
i += 1
Application.DoEvents()
Next
uneColonneoSheet.Columns.AutoFit()
j += 1
Application.DoEvents()
Next
uneLigne
Catch
End
Try
f.Dispose()
If
savefd1.ShowDialog() = System.Windows.Forms.DialogResult.OK
Then
Try
SaveAs(savefd1.FileName)
Catch
MessageBox.Show(
"erreur"
)
End
Try
End
If
oXL.Quit()
Return
True
End
FunctionEnd
Class
'''
<summary>
''' voila
'''
</summary>
'''
'''
<remarks></remarks>
Sub
test(
ByVal
datagv
As
DataGridView)
Dim
ex
As
New
nowex.Export(datagv)
ex =
Nothing
End
Sub
Bonjour chez vous !
Votre réponse
Discussions similaires
différence entre visual basic 6 et visual basic.net
andregoub
-
14 juil. 2006 à 18:44
Med365
-
26 juil. 2006 à 20:32
Générer un fichier PDF en C#
PolOw94
-
21 déc. 2010 à 10:10
miliaSing
-
24 janv. 2013 à 11:22
Visual Basic 5 gratuit vb5 gratuit!!!
SamuelCadieux
-
19 juin 2003 à 23:08
ilakan
-
6 juil. 2009 à 19:58
VBNET pause...sleep...pause...sleep...
bimbo777
-
22 mars 2006 à 15:10
eldim
-
22 mars 2006 à 15:38
Visual Basic Express > Portable
jordane45
-
14 juin 2010 à 10:02
us_30
-
18 juil. 2015 à 07:47
Rejoignez-nous