VB.net : MS Excel : Export Data : Good Looking Excel Sheet

  • Thread starter Thread starter Bre-x
  • Start date Start date
B

Bre-x

Guest
Good Morning All,

I have this data on my ms sql server

John Doe,Google Inc,2019,01,$1,200
John Doe,Google Inc,2019,02,$1,400
Dian Lik,Amazon Inc,2018,12,$4,500
Ross Dur,Microsoft ,2019,03,$9,000

How can I export to ms excel (see picture)

1418560.jpg


Dim xlFile As String = "C:\sco_apps\xls\quo_01.xlsx"
Dim xlApp As Microsoft.Office.Interop.Excel.Application = Nothing
Dim xlWorkBooks As Microsoft.Office.Interop.Excel.Workbooks = Nothing
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook = Nothing
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet = Nothing
Dim var_int As Integer = 0
Dim val_quo As Double

xlApp = New Microsoft.Office.Interop.Excel.Application
xlApp.DisplayAlerts = False
xlWorkBooks = xlApp.Workbooks
xlWorkBook = xlWorkBooks.Open(xlFile)
xlApp.Visible = False

Try
conn_app_start()
xlWorkSheet = xlWorkBook.Worksheets("Main")
app_cmd.CommandText = "select quo_cont,quo_cust, quo_y, qou_m,sum(quo_value) from c2sin_quomain group by quo_cont,quo_cust order by quo_cont;"
app_dr = app_cmd.ExecuteReader()
With xlWorkSheet
.Range("A6:E100").ClearContents()
var_int = 6
If app_dr.HasRows Then
While app_dr.Read()
.Cells(var_int, 1).Value = app_dr(0)
.Cells(var_int, 2).Value = app_dr(1)
var_int = var_int + 1
End While
End If
End With
app_dr.Close()

'Select
xlWorkSheet = xlWorkBook.Worksheets("Main")
xlWorkSheet.Select()

'End
xlApp.Visible = True
ReleaseComObject(xlWorkBook)
ReleaseComObject(xlWorkBooks)
ReleaseComObject(xlApp)
Catch ex As Exception
MsgBox("main : excel : " & Err.Description, MsgBoxStyle.Critical, app_cia)
Finally
conn_app_stop()
End Try

Thank you All,

John

Continue reading...
 
Back
Top