I'm generating an xls file from a datatable on a button click. Right now the path to save the file is hardcoded in the function to generate the file:
Function CreateExcelFile(xlFile As String) As Boolean
Try
Dim xlRow As Integer = 2
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim xlWB = xlApp.Workbooks.Add
Dim xlWS = xlApp.Worksheets.Add
Dim intStr As Integer = 0
Dim NewFile As String = ""
Dim strCaption As String = "PSLF Driver Files Records"
xlFile = Replace(xlFile, "Return Files", "Reports")
xlFile = Replace(xlFile, "txt", "xlsx")
xlFile = Replace(xlFile, "_", " ")
intStr = InStr(xlFile, "Reports")
xlApp.IgnoreRemoteRequests = True
xlWS = xlWB.Worksheets(xlApp.ActiveSheet.Name)
xlApp.DisplayAlerts = False
xlApp.Sheets.Add()
Dim xlTopRow As Integer = 2 'First Row to enter data
xlApp.Sheets.Add()
xlApp.Sheets(1).Name = strCaption
xlApp.Sheets(1).Select()
'Store datatable in 2-dimensional array
Dim arrExcel(frm_Records.BindingSource1.DataSource.Rows.Count, frm_Records.BindingSource1.DataSource.Columns.Count - 1) As String
'Write header row to array
arrExcel(0, 0) = "SSN"
arrExcel(0, 1) = "CREATE_DATE"
arrExcel(0, 2) = "SERVICER_CODE"
arrExcel(0, 3) = "STATUS"
arrExcel(0, 4) = "DRIVER_FILE_OUT"
arrExcel(0, 5) = "LAST_UPDATE_USER"
arrExcel(0, 6) = "LAST_UPDATE_DATE"
arrExcel(0, 7) = "CREATE_USER"
'Copy rows from datatable to array
xlRow = 1
For Each dr As DataRow In frm_Records.BindingSource1.DataSource.Rows
arrExcel(xlRow, 0) = dr("SSN")
arrExcel(xlRow, 1) = dr("CREATE_DATE")
arrExcel(xlRow, 2) = dr("SERVICER_CODE")
arrExcel(xlRow, 3) = dr("STATUS")
If IsDBNull(dr("DRIVER_FILE_OUT")) Then
arrExcel(xlRow, 4) = ""
Else
arrExcel(xlRow, 4) = dr("DRIVER_FILE_OUT")
End If
arrExcel(xlRow, 5) = dr("LAST_UPDATE_USER")
arrExcel(xlRow, 6) = dr("LAST_UPDATE_DATE")
arrExcel(xlRow, 7) = dr("CREATE_USER")
xlRow += 1
Next
'Set up range
Dim c1 As Microsoft.Office.Interop.Excel.Range = xlApp.Range("A1") 'Top left of data
Dim c2 As Microsoft.Office.Interop.Excel.Range = xlApp.Range("T" & frm_Records.BindingSource1.DataSource.Rows.Count - 1 + xlTopRow) 'Bottom right of data
Dim xlRange As Microsoft.Office.Interop.Excel.Range = xlApp.Range(c1, c2)
xlRange.Value = arrExcel 'Write array to range in Excel
xlWB.ActiveSheet.Range("A:T").Columns.Autofit()
xlWB.ActiveSheet.Range("A1:T1").Interior.Color = RGB(255, 255, 153)
xlWB.ActiveSheet.Range("A1:T1").Font.Bold = True
With xlApp.ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
xlApp.ActiveWindow.FreezePanes = True
Dim strSheet As String
For Each Sht In xlWB.Worksheets
If Sht.name Like "*Sheet*" Then
strSheet = Sht.name
xlApp.Sheets(strSheet).delete()
End If
Next
xlApp.IgnoreRemoteRequests = False
xlWB.SaveAs(xlFile)
xlWB.Close()
Dim xlHWND As Integer = xlApp.Hwnd
'this will have the process ID after call to GetWindowThreadProcessId
Dim ProcIdXL As Integer = 0
'get the process ID
GetWindowThreadProcessId(xlHWND, ProcIdXL)
'get the process
Dim xproc As Process = Process.GetProcessById(ProcIdXL)
xlApp.Quit()
'Release
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
'set to nothing
xlApp = Nothing
'kill it with glee
If Not xproc.HasExited Then
xproc.Kill()
End If
Catch ex As Exception
WP.WAPC_RUNSCRIPT_ERROR_FILE(WP.argScriptName, "Error Writing to Excel Report: " & ex.Message)
Return False
End Try
Return True
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, _
ByRef lpdwProcessId As Integer) As Integer
End Function
#End Region
What I want to do is upon completion of the creation of the Excel file, I want to give the user the option of where to save the newly created file. I'm new at
Winforms and am not sure how to do this.
What is the best way to enable the user to choose where to saved the file?
Update:
Working code after #Claudius' answer.
Private Sub btnRecExport_Click(sender As Object, e As EventArgs) Handles
btnRecExport.Click
Dim file As String = "I:\PSLFRecords.xlsx"
CreateExcelFile(file)
Dim sfdRecords As New SaveFileDialog()
sfdRecords.Filter = "Excel File|*.xls"
sfdRecords.Title = "Save PSLF Driver Records"
sfdRecords.ShowDialog()
If sfdRecords.FileName <> "" Then
xlWB.SaveAs(sfdRecords.FileName)
fs.Close()
End If
End Sub
From MSDN edited to your needs:
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
' Displays a SaveFileDialog so the user can save the Image
' assigned to Button2.
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "Excel File|*.xls
saveFileDialog1.Title = "Save an Excel File"
saveFileDialog1.ShowDialog()
' If the file name is not an empty string open it for saving.
If saveFileDialog1.FileName <> "" Then
xlWB.SaveAs(saveFileDialog1.FileName)
fs.Close()
End If
End Sub
All you'd actually need is just a new instance of the FolderBrowserDialog Class, that will return to you the path the user selected. All the information you need is already present in the documentation.
Related
Im fairly new to VB 2013. Any advice and help is greatly appreciated.
I have a datagridview that I want to export to Excel. I have the code working that does the export, but it doesnt show the header names. I need to edit the code to bring the header names over as well.
Additionally, I want to drop the first column from the export.
Example of my gridview code:
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim i As Integer
Dim j As Integer
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("Sheet1")
'Export Header Names Start
Dim columnsCount As Integer = DataGridView1.Columns.Count
For Each column In DataGridView1.Columns
xlWorkSheet.Cells(1, column.Index + 1).Value = column.name
Next
' 'Export Header Name End
For i = 0 To DataGridView1.RowCount - 2
For j = 0 To DataGridView1.ColumnCount - 1
xlWorkSheet.Cells(i + 1, j + 1) = _
DataGridView1(j, i).Value.ToString()
Next
Next
If System.IO.File.Exists("C:\test\export.xlsx") Then
System.IO.File.Delete("C:\test\export.xlsx")
End If
xlWorkSheet.SaveAs("C:\test\export.xlsx")
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
MsgBox("You can find the file here C:\test")
End Sub
DataGridview Output:
For many years i,m using this function.
Public Sub grid_ToExcel_Export(ByVal FileName As String, ByVal Data_GridView As DataGridView)
Dim sb As New System.Text.StringBuilder
Try
Dim intColumn, intColumnValue As Integer
Dim row As DataGridViewRow
For intColumn = 0 To Data_GridView.Columns.Count - 1
sb.Append(Data_GridView.Columns(intColumn).HeaderText)
If intColumnValue <> Data_GridView.Columns.Count - 1 Then
sb.Append(vbTab)
End If
Next
sb.Append(vbCrLf)
For Each row In Data_GridView.Rows
For intColumnValue = 0 To Data_GridView.Columns.Count - 1
sb.Append(StrConv(IIf(IsDBNull(row.Cells(intColumnValue).Value), "", row.Cells(intColumnValue).Value), VbStrConv.None))
If intColumnValue <> Data_GridView.Columns.Count - 1 Then
sb.Append(vbTab)
End If
Next
sb.Append(vbCrLf)
Next
SaveExcel(FileName, sb)
Catch ex As Exception
Throw
Finally
Data_GridView = Nothing
sb = Nothing
End Try
End Sub
Private Sub SaveExcel(ByVal fpath As String, ByVal sb As System.Text.StringBuilder)
Dim fsFile As New FileStream(fpath, FileMode.Create, FileAccess.Write)
Dim strWriter As New StreamWriter(fsFile, System.Text.Encoding.Unicode)
Try
With strWriter
.BaseStream.Seek(0, SeekOrigin.End)
.WriteLine(sb)
.Close()
End With
Catch e As Exception
msg(e.ToString)
Finally
sb = Nothing
strWriter = Nothing
fsFile = Nothing
End Try
End Sub
i'm using visual studio 2012 and microsoft SQL server 2012 to export datagridview to excel using this coding:
Public Class Export
Private Sub Export_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.AllowUserToAddRows = False
ClassKoneksi.namadatabase = "KPIRWAN"
Dim dssiswa As New DataSet
Dim sql As String
sql = "select*from Siswa order by NIS ASC"
dssiswa = ClassSiswa.displayData(ClassSiswa.opencon, sql, "DataSiswa")
DataGridView1.DataSource = dssiswa
DataGridView1.DataMember = "DataSiswa"
DataGridView1.ReadOnly = True
ClassSiswa.closecon()
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ExportExcel()
End Sub
Private Sub ExportExcel()
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim oValue As Object = System.Reflection.Missing.Value
Dim sPath As String = String.Empty
Dim dlgSave As New SaveFileDialog
dlgSave.DefaultExt = "xls"
dlgSave.Filter = "Microsoft Excel|*.xls"
dlgSave.InitialDirectory = Application.StartupPath
If dlgSave.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
xlApp = New Microsoft.Office.Interop.Excel.Application
xlBook = xlApp.Workbooks.Add(oValue)
xlSheet = xlBook.Worksheets("sheet1")
Dim xlRow As Long = 2
Dim xlCol As Short = 1
For k As Integer = 0 To DataGridView1.ColumnCount - 1
xlSheet.Cells(1, xlCol) = DataGridView1(k, 0).Value
xlCol += 1
Next
For k As Integer = 0 To DataGridView1.ColumnCount - 1
xlSheet.Cells(2, xlCol) = DataGridView1(k, 0).Value
xlCol += 1
Next
For i As Integer = 0 To DataGridView1.RowCount - 1
xlCol = 1
For k As Integer = 0 To DataGridView1.ColumnCount - 1
xlSheet.Cells(xlRow, xlCol) = DataGridView1(k, i).Value
xlCol += 1
Next
xlRow += 1
Next
xlSheet.Columns.AutoFit()
Dim sFileName As String = Replace(dlgSave.FileName, ".xlsx", "xlx")
xlSheet.SaveAs(sFileName)
xlBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlBook)
releaseObject(xlSheet)
MsgBox("Data successfully exported.", MsgBoxStyle.Information, "PRMS/SOB Date Tagging")
Catch
MsgBox(ErrorToString)
Finally
End Try
End If
End Sub
End Class
it work perfectly fine except when i exported the datagridview to excel the column header text in the datagridview is not exported to excel sheet only the gridview.
how do i make the coding to get the column header text to excel sheet?
I think you'll have to get the HeaderText from each column like this:
xlSheet.Cells(x,y).Value = DataGridView1.Columns(k).HeaderText
You would put this in your "k" loop. And then write it wherever you want in the file. x and y have to be the location where you write the header (maybe determined by k)
EDIT: writing the headers in first row of excel
For k As Integer = 0 To DataGridView1.ColumnCount - 1
xlSheet.Cells(1,k+1).Value = DataGridView1.Columns(k).HeaderText
Next
The code I am working on loads an XML file into a dataTable and displays it in a dataGridView. I then average each column in the dataGridView and display them as a new row in the dataGridView. I then export the dataGridView as an Excel file, however it is does not include the added average row. Any input that is manually entered into the dataGridView does get saved in the export? I understand that with SQL databases, you must call an update on the dataGridView source. I am not quite sure what to do in this case. Any ideas on how I can get the changes to be saved?
Opens a XML file and loads it into dataGridView
Private Sub ExOpen_Click(sender As Object, e As EventArgs) Handles ExOpen.Click
' Uses a openFileDialog to find the file path for the file the user wishes to
' use. It then displays the path in a textBox. Load a DataTable with the
' information found in the XML file and then set it as the dataSource for the
' DataGridView()
OpenFileDialog1.FileName = Nothing
OpenFileDialog1.Filter = "XML|*.xml"
If OpenFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
lblExFile.Text = OpenFileDialog1.FileName
End If
Dim dtDataTbl As New System.Data.DataTable
Dim dsDataSet As New DataSet
For Each dtDataTbl In dsDataSet.Tables
dtDataTbl.BeginLoadData()
Next
Try
dsDataSet.ReadXml(lblExFile.Text)
For Each dtDataTbl In dsDataSet.Tables
dtDataTbl.EndLoadData()
Next
DataGridView1.DataSource = dtDataTbl
Catch
Finally
dsDataSet = Nothing
dtDataTbl = Nothing
End Try
End Sub
Performs average of columns and adds it as a new row in dataGridView
Private Sub ExAvg_Click(sender As Object, e As EventArgs) Handles ExAvg.Click
' Goes through each column and finds the average. The averages are printed out
' into the DataGridView.
Dim decAvg As Decimal = 0
Dim sValue As String = Nothing
Dim sAppend As String = Nothing
Dim iCount As Integer = 0
For iColumn As Integer = 1 To DataGridView1.Columns.Count - 1
iCount = 0
For iRow As Integer = 0 To DataGridView1.Rows.Count - 1
sAppend = Nothing
If Not DataGridView1.Rows(iRow).Cells(iColumn).Value Is Nothing Then
sValue = CStr(DataGridView1.Rows(iRow).Cells(iColumn).Value)
Dim cChars() As Char = sValue.ToCharArray()
' Each character is only taken if a digit or "."
For Each cCharacter In cChars
If Char.IsDigit(cCharacter) OrElse cCharacter = "." Then
sAppend &= cCharacter
End If
Next
iCount += 1
decAvg += CDec(sAppend)
End If
Next
decAvg = Math.Round(decAvg / iCount, 2)
' Print the average row in the DataGridView.
Try
If iColumn = 1 Then
DataGridView1.Rows(iCount).Cells(iColumn).Value = "$" & CStr(decAvg)
Else
DataGridView1.Rows(iCount).Cells(iColumn).Value = CStr(decAvg)
End If
DataGridView1.Rows(iCount).Cells(0).Value = "Average"
Catch
End Try
Next
DataGridView1.v()
End Sub
Exports the dataGridView as an Excel file(missing added average row)
Private Sub ExSave_Click(sender As Object, e As EventArgs) Handles ExSave.Click
' Information from the DataGridView is transferred into an excel object
' row by row and column by column. The file name is picked by the user
' using a saveFileDialog.
SaveFileDialog1.FileName = Nothing
SaveFileDialog1.Filter = "Excel File|*.xls"
If SaveFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
lblExFile.Text = SaveFileDialog1.FileName
End If
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = CType(xlWorkBook.Worksheets(1), Excel.Worksheet)
Dim dc As DataColumn
Dim dr As DataRow
Dim dt As System.Data.DataTable
dt = CType(DataGridView1.DataSource, System.Data.DataTable)
Dim colIndex As Integer = 0
Dim rowIndex As Integer = 0
Try
'Export the Columns to excel file
For Each dc In dt.Columns
colIndex = colIndex + 1
xlWorkSheet.Cells(1, colIndex) = dc.ColumnName
Next
'Export the rows to excel file
For Each dr In dt.Rows
rowIndex = rowIndex + 1
colIndex = 0
For Each dc In dt.Columns
colIndex = colIndex + 1
xlWorkSheet.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
Next
Next
xlWorkSheet.Columns.AutoFit()
xlWorkBook.SaveAs(lblExFile.Text, XlFileFormat.xlWorkbookNormal, Type.Missing, _
Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlExclusive, _
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
xlWorkBook.Close()
You are adding the average to the GridView but write the datatable to Excel.
This is my code:
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "Excel files (*.xls)|*.xls"
saveFileDialog1.Title = "Save File"
saveFileDialog1.RestoreDirectory = True
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
Try
Dim ExcelApp As New Microsoft.Office.Interop.Excel.Application()
ExcelApp.Application.Workbooks.Add(Type.Missing)
ExcelApp.Cells.HorizontalAlignment = XlHAlign.xlHAlignLeft
' Change properties of the Workbook
ExcelApp.Columns.ColumnWidth = 15
' Storing header part in Excel
For i As Integer = 1 To DataGridView1.Columns.Count
ExcelApp.Cells(1, i) = DataGridView1.Columns(i - 1).HeaderText
Next
' Storing Each row and column value to excel sheet
For i As Integer = 0 To DataGridView1.Rows.Count - 2
For j As Integer = 0 To DataGridView1.Columns.Count - 1
ExcelApp.Cells(i + 2, j + 1) = DataGridView1.Rows(i).Cells(j).Value.ToString()
Next
Next
Dim Destinationpath As String = saveFileDialog1.FileName
ExcelApp.ActiveWorkbook.SaveAs(Destinationpath)
ExcelApp.ActiveWorkbook.Saved = True
ExcelApp.Quit()
MsgBox("Record exported successfully", MsgBoxStyle.Information)
Catch
MsgBox("It is being used by another process.Please close it and retry.", MsgBoxStyle.Critical)
End Try
Else
End If
Now how do I select the range using the above code which is populated in an excel sheet.
Found the answer:
Dim lastrow As Range = ExcelApp.Rows.End(XlDirection.xlDown)
Dim findme As Range = ExcelApp.Range("A1:E" & lastrow.Row)
MsgBox("A1:E" & lastrow.Row)
I have a problem when I export a flexgrid to excel from vb.net vs2008 to office 2010 english version an excel file is opened but it is empty. However, when I use office french version it is opened [correctly]
My code is:
On Error GoTo ErrorHandler
Dim iRow As Short
Dim iCol As Short
Dim objExcl As Excel.Application
Dim objWk As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim iHead As Short
Dim vHead As Object
objExcl = New Excel.Application
objExcl.Visible = True
objExcl.UserControl = True
Dim oldCI As System.Globalization.CultureInfo = _
System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = _
New System.Globalization.CultureInfo("en-US")
objWk = objExcl.Workbooks.Add
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
objSht = objWk.Sheets(1)
vHead = Split(g.FormatString, "|")
'populate heading in the sheet
'take the column heading from flex grid and put it in the sheet
For iHead = 1 To UBound(vHead)
If Len(Trim(vHead(iHead))) > 0 Then objSht.Cells._Default(1, iHead) = vHead(iHead)
Next
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
For iRow = 0 To g.Rows - 1
For iCol = 0 To g.get_Cols() - 1
g.Row = iRow
g.Col = iCol
'
'If g.Text <> "" Then objSht.Cells._Default(iRow + 2, iCol + 1) = g.Text
If g.Text <> "" Then
objSht.Range(NumCol2Lattre(iCol + 1) & "" & iRow + 2 & ":" & NumCol2Lattre(iCol + 1) & "" & iRow + 2 & "").Select()
objExcl.ActiveCell.Value = g.Text
End If
Next iCol
Next iRow
objExcl.Application.Visible = True
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
objSht = Nothing
objWk = Nothingl may not be destroyed until it is garbage collected. Click
objExcl = Nothing
Exit Sub
ErrorHandler:
objSht = Nothing
objWk = Nothing
objExcl = Nothing
MsgBox("Error In expotation task & " & Err.Description, MsgBoxStyle.Information)
Err.Clear()
Check out this website Exporting MSFlexGrid to Excel
I suspect your problem is with vHead = Split(g.FormatString, "|") Use the debugger to find out what is the value of g.FormatString. Is it causing an error? Step through the code one line at a time and see what happens.
On Error GoTo ErrorHandler
Imports System.Data
Imports System.IO
Imports System.Web.UI
Partial Class ExportGridviewDatainVB
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGridview()
End If
End Sub
Protected Sub BindGridview()
Dim dt As New DataTable()
dt.Columns.Add("UserId", GetType(Int32))
dt.Columns.Add("UserName", GetType(String))
dt.Columns.Add("Education", GetType(String))
dt.Columns.Add("Location", GetType(String))
dt.Rows.Add(1, "SureshDasari", "B.Tech", "Chennai")
dt.Rows.Add(2, "MadhavSai", "MBA", "Nagpur")
dt.Rows.Add(3, "MaheshDasari", "B.Tech", "Nuzividu")
dt.Rows.Add(4, "Rohini", "MSC", "Chennai")
dt.Rows.Add(5, "Mahendra", "CA", "Guntur")
dt.Rows.Add(6, "Honey", "B.Tech", "Nagpur")
gvDetails.DataSource = dt
gvDetails.DataBind()
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
' Verifies that the control is rendered
End Sub
Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.ClearContent()
Response.Buffer = True
Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", "Customers.xls"))
Response.ContentType = "application/ms-excel"
Dim sw As New StringWriter()
Dim htw As New HtmlTextWriter(sw)
gvDetails.AllowPaging = False
BindGridview()
'Change the Header Row back to white color
gvDetails.HeaderRow.Style.Add("background-color", "#FFFFFF")
'Applying stlye to gridview header cells
For i As Integer = 0 To gvDetails.HeaderRow.Cells.Count - 1
gvDetails.HeaderRow.Cells(i).Style.Add("background-color", "#df5015")
Next
gvDetails.RenderControl(htw)
Response.Write(sw.ToString())
Response.[End]()
End Sub
End Class