Mettre le contenu de labels dans tableau excel

KIPRE74 Messages postés 120 Date d'inscription jeudi 15 mai 2008 Statut Membre Dernière intervention 21 novembre 2013 - 1 août 2008 à 09:37
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 - 1 août 2008 à 15:19
Boonjour à tous !
Dans mon application, jai des labels qui contiennent des valeurs. Est-il possible de mettre le contenu de chaque label dans une colonne d'un tableau excel?
Si oui, la mise de nouvelles valeurs dans les labels précédents peuvent-elles être mises la la suite des précédentes valeurs de la même feuille excel ?

Merci pour votre aide

7 réponses

gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
1 août 2008 à 10:13
Dans mon application, j'ai des labels qui contiennent des valeurs. Est-il possible de mettre le contenu de chaque label dans une colonne d'un tableau excel?

oui c'est possible

Si oui,  la mise de nouvelles valeurs dans les labels précédents peuvent-elles être mises la la suite des précédentes valeurs de la même feuille excel ?

oui elles peuvent

bonjour chez vous!
< body>
0
KIPRE74 Messages postés 120 Date d'inscription jeudi 15 mai 2008 Statut Membre Dernière intervention 21 novembre 2013
1 août 2008 à 10:19
Je ne sais pas comment le faire
0
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
1 août 2008 à 10:23
quelle est la version d'excel avec laquelle tu travailles?

bonjour chez vous!
< body>
0
KIPRE74 Messages postés 120 Date d'inscription jeudi 15 mai 2008 Statut Membre Dernière intervention 21 novembre 2013
1 août 2008 à 10:36
Je travaille avec la version 2003
Mais sur un autre poste j'ai la version d'évalution 2007

Merci
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
1 août 2008 à 10:53
mets les valeurs de tes labels dans une datagridview et hop
' * 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
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)

TryoWB.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

Falsepgb.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 =

TrueoRng.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
Tryf.Dispose()

If savefd1.ShowDialog() = System.Windows.Forms.DialogResult.OK
Then

TrySaveAs(savefd1.FileName)

CatchMessageBox.Show(

"erreur")

End
Try

End
IfoXL.Quit()

Return
True

End
FunctionEnd

Class

bonjour chez vous!
< body>
0
KIPRE74 Messages postés 120 Date d'inscription jeudi 15 mai 2008 Statut Membre Dernière intervention 21 novembre 2013
1 août 2008 à 15:02
Rebonjour, je n'arrive pas à insérer le contenu de mes labels dans le dataGridView. Je les ai mis dans des variables le faire mais j'ai un message d'erreur "String cannot be converted to System.Windows.Form.Datagrid"
Je ne sais comment procéder !
0
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
1 août 2008 à 15:19
datagridview.Rows.Add(label1.text, label20.text)

bonjour chez vous!
< body>
0
Rejoignez-nous