Hi All,
I does have a question about export datagrid data to csv. Well, I know the common solution is
1) select the data again and put in the datatable, then export to csv.
BUT I don't want this, I want DIRECTLY export what I saw in datagrid to CSV, because some of the value I changed in database before I display in the datagrid,
does anyone can help me on this?
You need VB code or C# code
VB code
Public Sub create_csv(flx As MSHFlexGrid)
Dim str1 As String
Open App.Path & "\export.csv" For Output As #1 ' Open file for output.
For i = 0 To flx.Rows - 1
str1 = ""
For j = 0 To flx.Cols - 1
str1 = str1 & flx.TextMatrix(i, j) & " "
If j <> flx.Cols - 1 Then str1 = str1 & ","
Next
Print #1, str1
Next
Close #1
'Open the excel
openfile (flx.Cols)
End Sub
Public Sub openfile(thecols As Integer)
Dim objExcel As New Excel.Application
Dim objWorkBooks As Object
Dim objAsheet As Object
'On Error Resume Next
If Err.Number Then
Err.Clear
Set objExcel = CreateObject("Excel.Application")
End If
Set objWorkBooks = objExcel.Workbooks
objWorkBooks.Open App.Path & "\export.csv", , , 2, , , , , ","
objExcel.Visible = True
For intcol = 1 To thecols
'objExcel.Columns(intCol).AutoFit()
objExcel.Columns(intcol).AutoFormat (2)
objExcel.Range("a1", (objExcel.Columns(thecols).AddressLocal) & TheRows).AutoFormat (GridStyle)
Next
End Sub
use data Grid for Flex grid