Hi,
With the below code its successfully exporting to excel.
i want two things from below code
1) When Status="VALID" then background color should be green and when "NOTDONE" then red
2) After
For Each dt As DataTable In ds.Tables
wb.Worksheets.Add(dt)
Next
// here i want to add multiple custom rows on Employee name column
after adding all employee on that dataset
Protected Sub ExportExcel(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click, btnExport.Click
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim query As String = "SELECT EmployeeName,CourseNo,CourseName,Status FROM Employee"
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand(query)
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using ds As New DataSet()
sda.Fill(ds)
'Set Name of DataTables.
ds.Tables(0).TableName = "Employee"
Using wb As New XLWorkbook()
For Each dt As DataTable In ds.Tables
wb.Worksheets.Add(dt)
Next
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment;filename=" & Microsoft.VisualBasic.Strings.Format(Now, "dd-MMM-yyyy") & ".xlsx")
Using MyMemoryStream As New MemoryStream()
wb.SaveAs(MyMemoryStream)
MyMemoryStream.WriteTo(Response.OutputStream)
Response.Flush()
Response.End()
End Using
End Using
End Using
End Using
End Using
End Using
End Sub