Dim xlApp
As Excel.Application
Dim xlBook
As Excel.Workbook
Dim xlSheet
As Excel.Worksheet
xlApp =
CType(CreateObject("Excel.Application"), Excel.Application)
xlBook =
CType(xlApp.Workbooks.Add, Excel.Workbook)
xlSheet =
CType(xlBook.Worksheets(1), Excel.Worksheet)
'datatable pour récupérer le nom des colonnes du datagrid
Dim da
As
New DataTable
SQlDAviewer.Fill(da)
' mise des infos ds le datagrid
Dim nbrLigne
As
Integer = da.Rows.Count - 1
Dim nbrColon
As
Integer = da.Columns.Count - 1
Dim x, y
As
Integer
For x = 0
To nbrColon
'titres colonnes
xlSheet.Cells(1, x + 1) = da.Columns(x).ColumnName
xlSheet.Rows(1).Font.Bold =
True
' mise en gras
'données
For y = 0
To nbrLigne
xlSheet.Cells(y + 2, x + 1) = DataGrid1.Item(y, x)
Next
Next
' Show the sheet.
xlSheet.Application.Visible =
True
' Save the sheet to C:\Test.xls directory.
xlSheet.SaveAs("C:\LPDataViewer.xls")
' Optionally, you can call xlApp.Quit to close the work sheet.
xlSheet =
Nothing
xlBook =
Nothing
xlApp =
Nothing
da =
Nothing