I have code to export to Excel, in Green highlight below. this works perfect.
I added message in a label (yellow highlight) to show how many records to expect. This does nothing. Something with the page refresh and the Save or Open box showing at the bottom of the page will not let anything on screen occur.
If I skip the green code using the "Exit sub" then the message in the yellow code works just fine.
Can someone guide me ?
TIA
I added message in a label (yellow highlight) to show how many records to expect. This does nothing. Something with the page refresh and the Save or Open box showing at the bottom of the page will not let anything on screen occur.
If I skip the green code using the "Exit sub" then the message in the yellow code works just fine.
Can someone guide me ?
TIA
Code:
'fill grid with data based on options choosen
Dim TheMonth As String = ""
TheMonth = Trim(Left(Me.ddlChooseMonth.Text, InStr(1, Me.ddlChooseMonth.Text, " -") - 1))
Dim TheVendor As String = ""
Dim SOWTracker As String = ""
Dim queryTrans As String
If Me.ddlChooseVendor.Text <> "Choose..." Then
TheVendor = Trim(Left(Me.ddlChooseVendor.Text, InStr(1, Me.ddlChooseVendor.Text, " -") - 1))
SOWTracker = Trim(Right(Me.ddlChooseVendor.Text, Len(Me.ddlChooseVendor.Text) - InStr(1, Me.ddlChooseVendor.Text, "- ")))
End If
Dim TheYear As String = Me.ddlChooseYear.Text
If TheMonth = 13 Then
queryTrans = YearToDate()
Else
queryTrans = CreateExportToExcelSQLString(TheVendor, SOWTracker, TheMonth, TheYear)
[highlight #FCE94F] Me.lblRecordsExported.Text = CountRecords(TheVendor, SOWTracker, TheMonth, TheYear)
Me.lblRecordsExported.Visible = True[/highlight]
End If
'Exit Sub
Dim tbl As DataTable
tbl = PopulateGridwithSQL(queryTrans)
Dim pck As ExcelPackage = New ExcelPackage()
Dim Vendorname As String = Right(ddlChooseVendor.Text, Len(ddlChooseVendor.Text) - InStr(1, ddlChooseVendor.Text, "- "))
If Vendorname = "Choose..." Then
Vendorname = ""
Else
Vendorname = Vendorname & "_"
End If
Dim Monthname As String = Trim(Right(Me.ddlChooseMonth.Text, Len(Me.ddlChooseMonth.Text) - InStr(1, Me.ddlChooseMonth.Text, "- ")))
Dim MonthYear As String = Monthname & "_" & Me.ddlChooseYear.Text
Dim ExcelFilename As String = Vendorname & MonthYear & " SOW Time Reporting"
Dim Tabname As String = Vendorname & MonthYear
'Create the worksheet
[highlight #8AE234] Dim ws As ExcelWorksheet = pck.Workbook.Worksheets.Add(Tabname)
'Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells("A1").LoadFromDataTable(tbl, True)
'Write it back to the client
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + ExcelFilename + ".xlsx")
HttpContext.Current.Response.BinaryWrite(pck.GetAsByteArray())
HttpContext.Current.Response.End()
pck = Nothing[/highlight]
DougP