in my datagridview I have the first column visible = false. I need that this column not export to excel
I have the following code to export to excel:
If Sfd.ShowDialog() = DialogResult.OK Then
Dim App As New Excel.Application
Dim WB As Excel.Workbook
Dim WS As New Excel.Worksheet
WB = App.Workbooks.Add()
WS = WB.ActiveSheet
For i As Integer = 1 To DG.Columns.Count
WS.Cells(1, i) = DG.Columns(i - 1).HeaderText
Next
For i As Integer = 0 To DG.Rows.Count - 1
For j As Integer = 0 To DG.Columns.Count - 1
WS.Cells(i + 2, j + 1) = DG.Rows(i).Cells(j).Value.ToString()
WS.Cells(i + 2, 1).Font.Color = Color.Blue
Next
Next
With WS
With .Range(.Cells(1, 1), .Cells(1, DG.ColumnCount)).Font
.Color = Color.White
.Bold = 1
.Size = 12
End With
.Range(.Cells(1, 1), .Cells(1, DG.ColumnCount)).Interior.Color = Color.Black
.Columns.AutoFit()
.Columns.HorizontalAlignment = 2
End With
WB.SaveAs(Sfd.FileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal)
WB.Close()
Process.Start(Sfd.FileName)
End If
Thanks