Bonjour à tous,
Je souhaiterais supprimer une plage de ligne d'un fichier XLS dans une application VB.NET, en parcourant internet j'ai trouvé quelques bouts de codes mais aucun de fonctionnel dans mon cas même avec les modifications que j'ai trouvé sur internet :
Mes imports :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 Imports System.Data.OleDb Imports Microsoft.Office.Interop.Excel Imports Microsoft.Office.InteropCelui ci me donne l'erreur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 'Instantiate a Workbook object. Dim workbook As Workbook workbook = New Workbook() 'workbook = New Workbook() 'Load a template file. workbook.Open(destination) 'Get the first worksheet in the book. Dim sheet1 As Worksheet = workbook.Worksheets(1) sheet1.Cells.DeleteRows(10, 200) Dim sheet2 As Worksheet = workbook.Worksheets(2) sheet2.Cells.DeleteRows(10, 200) 'Save the excel file. workbook.Save()80040154 La récupération de la fabrique de classe COM pour le composant avec le CLSID" sur la ligne "workbook = New Workbook()
Et cet autre code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 Dim oExcel As New Microsoft.Office.Interop.Excel.Application Dim oBook As Microsoft.Office.Interop.Excel.Workbook Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet oBook = oExcel.Workbooks.Open(destination) oSheet = oBook.Worksheets(2) Dim rg1 As Excel.Range = oSheet.Rows("10:10") ' delete the specific row rg1.Select() rg1.Delete() oBook.Save() oExcel.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel) oBook = Nothing oExcel = Nothing
Me donne cette erreurAuriez vous des pistes sur un code utilisable ou des conseils pour faire fonctionner ces codes ?La méthode Select de la classe Range a échoué." sur la ligne "rg1.Select()
D'avance merci !
Partager