وضعت هذا الكود لتصدير البيانات من داتا غريد فيو الى اكسل ولكن واجهتني مشكلة بسيطة وهي تصديره لاسماء الاعمدة بدون البيانات
ما السبب ؟؟؟؟؟؟؟؟
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
Dim xlApp As Object
Dim xlWb As Object
Dim xlWs As Object
Dim data(1)() 'two dimension array
Dim fldCount As Integer
Dim recCount As Long
Dim iCol As Integer
Dim iRow As Integer
' Create an instance of Excel and add a workbook
xlApp = CreateObject("Excel.Application")
xlWb = xlApp.Workbooks.Add
xlWs = xlWb.Worksheets("Sheet1")
' Copy field names to the first row of the worksheet
fldCount = DataGridViewX1.ColumnCount
ReDim data(0)(fldCount)
For iCol = 1 To fldCount
xlWs.Cells(1, iCol).Value = DataGridViewX1.Columns(iCol - 1).HeaderText
Next
' Copy data to the rest rows of the worksheet
recCount = DataGridViewX1.Rows.Count
For iRow = 2 To recCount
For iCol = 1 To fldCount
data(0)(iCol - 1) = Me.DataGridViewX1.Rows(iRow - 1).Cells(iCol - 1).Value
Next
xlWs.Range(xlWs.Cells(iRow, 1), xlWs.Cells(iRow, iCol - 1)).Value = data(0)
Next
' Auto-fit the column widths and row heights
xlApp.Selection.CurrentRegion.Columns.AutoFit()
xlApp.Selection.CurrentRegion.Rows.AutoFit()
' Display Excel and give user control of Excel's lifetime
xlApp.Visible = True
xlApp.UserControl = True
' Release Excel references
xlWs = Nothing
xlWb = Nothing
xlApp = Nothing


