Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim xlSheet1 As Microsoft.Office.Interop.Excel.Worksheet
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim G As Integer
Dim R As Integer
Dim C As Integer
Dim RowNum As Integer
Dim RowHide As Integer
RowNum = 1
For G = 0 To grdData.Count - 1
RowHide = 0
For C = 0 To grdData(G).Columns.Count - 1 Gen Header
With xlApp
.Cells(RowNum, C + 1 - RowHide) = pClass.Format_Data(grdData(G).Columns(C).HeaderText)
.Range((RowNum).ToString + ":" + (RowNum).ToString).Font.Bold = True
.Range((RowNum).ToString + ":" + (RowNum).ToString).Interior.Color = RGB(0, 176, 240)
.Range((RowNum).ToString + ":" + (RowNum).ToString).EntireColumn.AutoFit()
End With
If (grdData(G).Columns(C).Visible = False) Or (grdData(G).Columns(C).HeaderText = "") Then
RowHide = RowHide + 1
End If
Next
RowHide = 0
For R = 0 To grdData(G).Rows.Count - 1
For C = 0 To grdData(G).Columns.Count - 1
With xlApp
.Cells(RowNum + R + 1, C + 1 - RowHide) = pClass.Format_Data(grdData(G).Rows(R).Cells(C).Text)
.Range((RowNum + R + 1).ToString + ":" + (C + 1 - RowHide).ToString).EntireColumn.AutoFit()
End With
If (grdData(G).Columns(C).Visible = False) Or (grdData(G).Columns(C).HeaderText = "") Then
RowHide = RowHide + 1
End If
Next
RowHide = 0
Next
RowNum = RowNum + R + 2
Next
xlBook.Application.Visible = True
Tag : .NET, Excel (Excel.Application), Web (ASP.NET), VB.NET