Dim iLigne As Integer
' Récupérer l'élément actuellement sélectionné
iLigne = Dgv.Rows.GetFirstRow(DataGridViewElementStates.Selected)
' Tout sélectionner
Dgv.SelectAll()
' Le mettre en mémoire ClipBoard
Clipboard.SetDataObject(Dgv.GetClipboardContent())
' Remettre la sélection précédente
While Dgv.Rows.GetFirstRow(DataGridViewElementStates.Selected) > -1
Dgv.Rows(Dgv.Rows.GetFirstRow(DataGridViewElementStates.Selected)).Selected = False
End While
Dgv.Rows(iLigne).Selected = True
' Coller le datagrid dans Excel
objFeuille.Cells.PasteSpecial(Excel.XlPasteType.xlPasteAll, Excel.XlPasteSpecialOperation.xlPasteSpecialOperationAdd)
' Rendre visible Excel
objXL.Visible = True
objXL.UserControl = True
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
cs_yasmina28
Messages postés1Date d'inscriptionsamedi 12 septembre 2009StatutMembreDernière intervention14 septembre 2009 14 sept. 2009 à 00:18
Bonjour
j'ai essaé ce code mais j'ai un petit problème je crois que j'ai oublié de rajouter un dll mais je sais pas laquelle
le problème est: quand j'éxécute il ne reconnait pas la méthode SaveAs
pactoopac
Messages postés9Date d'inscriptionsamedi 9 juin 2007StatutMembreDernière intervention22 mars 2010 24 juil. 2009 à 15:23
attention si le dataGridView a plus de 26 colonnes!!
en bircolant un peut, voici une petite solution pour les tableaux avec moins de 676 colonnes.
Pour la première boucle :
if (i < 26)
oRng = oSheet.get_Range(Convert.ToChar(65 + i).ToString() + "1", Missing.Value);
else
{
oRng = oSheet.get_Range(Convert.ToChar(65 + ii).ToString() + Convert.ToChar(65 + i%26).ToString() + "1", Missing.Value);
if ((i%26).Equals(0))
ii++;
}
a_alexandrov
Messages postés2Date d'inscriptionlundi 20 août 2007StatutMembreDernière intervention20 août 2007 20 août 2007 à 14:33
use DataGridView Extension - it is free and gives you the ability to export to Excel, Html, soon Pdf (they say). Also you can search for text, save some settings as a theme, make all controls look and behave the same very easy.
22 juil. 2011 à 23:07
21 avril 2010 à 00:32
24 mars 2010 à 15:09
Merci beaucoup pour ce code. Est ce que quelqu'un peut m'expliquer comme exporter un DataGridView vers un fichier Word?
6 nov. 2009 à 15:41
Public Sub ExporterVersExcel(ByRef Dgv As DataGridView)
Dim objXL As Excel.Application
Dim objClasseur As Excel.Workbook
Dim objFeuille As Excel.Worksheet
Try
' Lancer Excel
objXL = New Excel.Application
objXL.DisplayAlerts = False
objClasseur = objXL.Workbooks.Add(1)
objFeuille = objClasseur.Sheets(1)
Dim iLigne As Integer
' Récupérer l'élément actuellement sélectionné
iLigne = Dgv.Rows.GetFirstRow(DataGridViewElementStates.Selected)
' Tout sélectionner
Dgv.SelectAll()
' Le mettre en mémoire ClipBoard
Clipboard.SetDataObject(Dgv.GetClipboardContent())
' Remettre la sélection précédente
While Dgv.Rows.GetFirstRow(DataGridViewElementStates.Selected) > -1
Dgv.Rows(Dgv.Rows.GetFirstRow(DataGridViewElementStates.Selected)).Selected = False
End While
Dgv.Rows(iLigne).Selected = True
' Coller le datagrid dans Excel
objFeuille.Cells.PasteSpecial(Excel.XlPasteType.xlPasteAll, Excel.XlPasteSpecialOperation.xlPasteSpecialOperationAdd)
' Rendre visible Excel
objXL.Visible = True
objXL.UserControl = True
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
14 sept. 2009 à 00:18
j'ai essaé ce code mais j'ai un petit problème je crois que j'ai oublié de rajouter un dll mais je sais pas laquelle
le problème est: quand j'éxécute il ne reconnait pas la méthode SaveAs
24 juil. 2009 à 15:23
en bircolant un peut, voici une petite solution pour les tableaux avec moins de 676 colonnes.
Pour la première boucle :
if (i < 26)
oRng = oSheet.get_Range(Convert.ToChar(65 + i).ToString() + "1", Missing.Value);
else
{
oRng = oSheet.get_Range(Convert.ToChar(65 + ii).ToString() + Convert.ToChar(65 + i%26).ToString() + "1", Missing.Value);
if ((i%26).Equals(0))
ii++;
}
pour la seconde :
if (i < 26)
oRng = oSheet.get_Range(Convert.ToChar(65 + i).ToString() + j.ToString(), Missing.Value);
else
{
oRng = oSheet.get_Range(Convert.ToChar(65 + ii).ToString() + Convert.ToChar(65 + i%26).ToString() + j.ToString(), Missing.Value);
if ((i % 26).Equals(0))
ii++;
}
20 août 2007 à 14:33
http://www.completit.com/Products/DGVE/Overview.aspx
Hope it will be helpfull.
19 juil. 2007 à 19:06
6 nov. 2006 à 18:43
5 nov. 2006 à 22:00