1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| Dim OApp As Excel.Application
'Create an Excel instalce.
'Créer un instalce Excel.
Try
OApp = DirectCast(CreateObject("Excel.Application"), Excel.Application)
'Open the csv file 'Ouvrez le fichier csv
OApp.Workbooks.OpenText(Filename:="C:\Documents and Settings\hp\Bureau\TextversEXCEL\Projet1.NET1\bin\Report-nEWpOSTE.txt", _
Origin:=Excel.XlPlatform.xlMSDOS, _
DataType:=Excel.XlTextParsingType.xlDelimited, _
Comma:=False, Space:=False, Tab:=False, Other:=True, StartRow:=1)
OApp.Visible = True
'Now lets SaveAs to convert it to an xls file format. «Maintenant passons à SaveAs pour le convertir dans un format de fichier xls.
OApp.Workbooks.Item("Report-nEWpOSTE.txt").SaveAs(Filename:="C:\Test.xls", _
FileFormat:=Excel.XlFileFormat.xlWorkbookNormal)
'Now lets close the workbook. "Passons d'abord fermer le classeur. No need to save the changes as we just did a saveas Pas besoin de sauvegarder les modifications que nous avons juste fait un SaveAs
OApp.Workbooks.Item("Test.xls").Close(SaveChanges:=False)
'Quit Excel 'Quit Excel
OApp.Quit()
OApp = Nothing
MessageBox.Show("Done", "Done", MessageBoxButtons.OK)
Catch ex As Exception
MessageBox.Show(ex.Message.ToString, "Error", MessageBoxButtons.OK)
End Try |
Partager