Erreur sur l'exportation d'une listview

Résolu
trucss Messages postés 189 Date d'inscription jeudi 17 février 2022 Statut Membre Dernière intervention 23 janvier 2024 - 18 juil. 2023 à 10:07
Whismeril Messages postés 19030 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 27 avril 2024 - 18 juil. 2023 à 20:32

Bonjour,

J'exporte les données d'une listview vers Excel ça fonctionne mais j'ai des erreurs quand je régénère la solution c'est aléatoire.

 Public Sub subExporterExcel(ByVal lvw As ListView)

        Try
            Dim xla As New Microsoft.Office.Interop.Excel.Application()
            xla.Visible = True

            Dim wb As Microsoft.Office.Interop.Excel.Workbook = xla.Workbooks.Add(Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet)
            Dim ws As Microsoft.Office.Interop.Excel.Worksheet = DirectCast(xla.ActiveSheet, Microsoft.Office.Interop.Excel.Worksheet)
            Dim ligne As Integer = 1
            Dim colonne As Integer = 1
            Dim jj As Integer = lvw.Columns.Count

            For rr = 0 To lvw.Columns.Count - 1
                ws.Cells(ligne, colonne) = lvw.Columns(rr).Text
                colonne = colonne + 1
            Next

            ligne = 2
            colonne = 1
            For Each comp As ListViewItem In lvw.Items
                ws.Cells(ligne, colonne) = comp.Text.ToString()
                For Each drv As ListViewItem.ListViewSubItem In comp.SubItems
                    ws.Cells(ligne, colonne) = drv.Text.ToString()
                    colonne += 1
                    ws.Columns.AutoFit()

                Next
                colonne = 1
                ligne += 1

            Next
        Catch ex As Exception

        End Try
    End Sub

1 réponse

Whismeril Messages postés 19030 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 27 avril 2024 656
18 juil. 2023 à 20:32

Dans ma boule de cristal, j'ai l'impression qu'il manque une pinte à la ligne 1664.

Mais c'est aléatoire.


Non, mais franchement, comment veux-tu qu'on réponde à ça, si tu ne copies pas les messages d'erreur ?

D'autre part, merci de choisir "Basic" comme langage quand tu postes un code.


1
Rejoignez-nous