excel.Workbooks.Close()
excel.Quit()
excel = Nothing
je ne sait pas comment faire pour déplacer toutes les premières lignes de la feuille excel pour le ramener vers le bas
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question'Deplacer up down Private Sub MoveRow(ByVal i As Integer) Try If (DataGridView1.SelectedCells.Count > 0) Then Dim curr_index As Integer = DataGridView1.CurrentCell.RowIndex Dim curr_col_index As Integer = DataGridView1.CurrentCell.ColumnIndex Dim curr_row As DataGridViewRow = DataGridView1.CurrentRow DataGridView1.Rows.Remove(curr_row) DataGridView1.Rows.Insert(curr_index + i, curr_row) DataGridView1.CurrentCell = DataGridView1(curr_col_index, curr_index + i) End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub 'monter item Private Sub cmdup_Click(sender As System.Object, e As System.EventArgs) Handles cmdup.Click If DataGridView1.CurrentCell.RowIndex = 0 Then Exit Sub End If MoveRow(-1) ' move up in the datagridview (row index is 1 less) cmdsave.Enabled = True modif = True End Sub 'descendre item Private Sub cmddown_Click(sender As System.Object, e As System.EventArgs) Handles cmddown.Click If DataGridView1.CurrentCell.RowIndex = DataGridView1.Rows.Count - 2 Then Exit Sub End If MoveRow(1) ' move down in the datagridview (row index is 1 more) cmdsave.Enabled = True modif = True End Sub
'enregistrer la bdd Private Sub cmdsave_Click(sender As System.Object, e As System.EventArgs) Handles cmdsave.Click Dim c As Integer Dim val As String If cmbfeuille.Text = "" Then Exit Sub xlApp.ScreenUpdating = False xlApp.DisplayAlerts = False xlWorkBook = xlApp.Workbooks.Open(chemin) xlWorkSheet = CType(xlWorkBook.Worksheets(cmbfeuille.Text), Excel.Worksheet) For l As Integer = 0 To DataGridView1.RowCount - 1 For c = 0 To DataGridView1.ColumnCount - 1 val = CStr(DataGridView1.Rows.Item(l).Cells(c).Value) xlWorkSheet.Cells(l + 2, c + 1) = val Next c Next l xlWorkSheet.Range("A:F").Columns.AutoFit() 'colonnes autoresizes xlApp.ScreenUpdating = True xlApp.DisplayAlerts = True xlWorkBook.Close() xlApp.Quit() modif = False End Sub
xlWorkSheet.Cells(l + 2, c + 1) = val
xlWorkSheet.Cells(l + 10, c + 1) = val