473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Export Datagrid data to CSV

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?
Feb 10 '07 #1
1 5639
hariharanmca
1,977 1GB
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
Feb 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Eric | last post by:
Dear All, I want to export datagrid content to a Excel file, the code just like below: Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Me.EnableViewState = False Dim...
2
by: Bidarkota | last post by:
Hi, I have a DataGrid in which there are some images and Data are displayed and in the webform.asp page i am using some stylesheets. when i export the datagrid all the images are also exported...
0
by: sunilkumar Reddy via DotNetMonster.com | last post by:
hai all first we have taken binded grid Export to excel data from ultrawebgrid (or) datagrid rows, Each row data Expoting to one worksheet in excel workbook, like as grid row1 data contain...
2
by: footballhead | last post by:
I have a page with a datagrid that I have configured with all the information I need to provide to froogle for listing my products on their site. I am having trouble finding a way to successfully...
6
by: Sridhar | last post by:
Hi, I have to export data inside the datagrid into an excel worksheet. I have to do this on button click event. I am trying to do like this. First get the DataTable from the datagrid and...
0
by: madhavit | last post by:
hi, i am able to export datagrid data to excel sheet but the problem is i am not able to export datagrid within datagrid data to excel. can anybody help me. thanx.
1
by: Kondapanaidu | last post by:
Hi, I am using .NET 1.1, How to Export the data from Datagrid to PDF file. Lets assume that EMP Table EmpNo Empname 1 AAA
1
by: Arch Stanton | last post by:
I export the contents of my datagrid controls to Excel using the following Sub: Sub WriteToExcel(Sender as Object, E as EventArgs) Response.Clear() Response.ContentType =...
5
by: Reggie | last post by:
Hi and TIA! I have an export procedure that exports my data from my datagrids to excel. The problem is that I lose leading zero's cause excel removes them and doesn't treat them as text. Is it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.