Author : Karthick
Date Submitted : 4/24/2006
Category : File Manipulation
Compatibility : VB 6,VB 5,VB 4/16
This code has been accessed 7422 times.
Task : Export Excel file in to MSFlexGrid
Declarations
Code
Private Sub command1_Click()
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\karthik\testfiles\bctest.xls;Extended Properties=Excel 8.0;Persist Security Info=False")
Set rs = con.Execute("select * from [bctest$]")
i = 1
MsFlexgrid1.Rows = 2
MsFlexgrid1.Cols = rs.Fields.Count
Do While Not rs.EOF
For j = 0 To rs.Fields.Count - 1
MsFlexgrid1.TextMatrix(0, j) = IIf(IsNull(rs.Fields(j).Name), "", rs.Fields(j).Name)
MsFlexgrid1.TextMatrix(i, j) = IIf(IsNull(rs.Fields(j).Value), "", rs.Fields(j).Value)
str = str + IIf(IsNull(rs.Fields(j).Value), "", rs.Fields(j).Value)
Next
i = i + 1
If MsFlexgrid1.Rows <= i Then
MsFlexgrid1.Rows = datagrid1.Rows + 1
End If
rs.MoveNext
Loop
Msflexgrid1.Rows = datagrid1.Rows - 1
Text1.Text = str
End Sub