473,395 Members | 1,456 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,395 software developers and data experts.

How to extract the records from datagrid to excel

2
I have developed an application for extracting records from datagrid to excel. Unfortunately, when i run this application, no records were extracted. If anybody knows what is lacking in my script then please inform me. Below is my script. Thanks a lot!!!

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmDExtract_Click()
  2.  
  3.     On Error GoTo ErrorLine
  4.     Screen.MousePointer = vbHourglass
  5.     Dim xl As Object
  6.     Dim wb As Object
  7.     Dim ws As Object
  8.     Dim i  As Long
  9.     Dim X  As Long
  10.  
  11.     Set xl = CreateObject("Excel.Application")
  12.     Set wb = xl.Workbooks.Add()
  13.     Set ws = xl.ActiveWindow.ActiveSheet
  14.     ws.Columns().ColumnWidth = 10
  15.  
  16.     For X = 0 To DataGrid1.Row - 1
  17.         DataGrid1.Row = X
  18.         DataGrid1.Col = 1
  19.             For i = 1 To DataGrid1.Col
  20.                 DataGrid1.Col = i
  21.                 If DataGrid1.Text <> "" Then
  22.                     ws.Cells(X, i) = DataGrid1.Text
  23.                     ws.Cells(X, i).HorizontalAlignment = -4131
  24.  
  25.                 End If
  26.             Next
  27.     Next
  28.     xl.Visible = True
  29. ErrorLine:
  30.     Screen.MousePointer = vbDefault
  31.  
  32. End Sub
May 7 '07 #1
1 1529
Dököll
2,364 Expert 2GB
I have developed an application for extracting records from datagrid to excel. Unfortunately, when i run this application, no records were extracted. If anybody knows what is lacking in my script then please inform me. Below is my script. Thanks a lot!!!

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmDExtract_Click()
  3.  
  4.     On Error GoTo ErrorLine
  5.     Screen.MousePointer = vbHourglass
  6.     Dim xl As Object
  7.     Dim wb As Object
  8.     Dim ws As Object
  9.     Dim i  As Long
  10.     Dim X  As Long
  11.  
  12.     Set xl = CreateObject("Excel.Application")
  13.     Set wb = xl.Workbooks.Add()
  14.     Set ws = xl.ActiveWindow.ActiveSheet
  15.     ws.Columns().ColumnWidth = 10
  16.  
  17.     For X = 0 To DataGrid1.Row - 1
  18.         DataGrid1.Row = X
  19.         DataGrid1.Col = 1
  20.             For i = 1 To DataGrid1.Col
  21.                 DataGrid1.Col = i
  22.                 If DataGrid1.Text <> "" Then
  23.                     ws.Cells(X, i) = DataGrid1.Text
  24.                     ws.Cells(X, i).HorizontalAlignment = -4131
  25.  
  26.                 End If
  27.             Next
  28.     Next
  29.     xl.Visible = True
  30. ErrorLine:
  31.     Screen.MousePointer = vbDefault
  32.  
  33.  
  34.  
  35. End Sub
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
Hey there, edgara!

Good of you to add your code in. It looks like you have not yet attempted to create a .xls file. If you have previously searched here and could not find anything, set your eyes on this:

http://www.developerfusion.co.uk/show/6072/

This should get you started. If not, please stay tuned. I cannot run anything from here just yet. Please stay tuned nonetheless, helpful members will likely see your information.

In a bit!

Dököll
May 7 '07 #2

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

Similar topics

9
by: Brian Hanson | last post by:
Hi, I have an unusual problem that just showed its ugly head at a pretty bad time. I have an asp.net (VB) app that takes data from an Excel sheet and puts it into SQL Server. I get the data...
2
by: Mardy | last post by:
Hello I'm working on code to upload an Excel file, read the spreadsheet contents into a datagrid, then ultimately insert each row into a sql server database. Currently I have the file upload...
3
by: TM | last post by:
Is there any way that I can take the records from a datagrid and paste them into an Excel sheet, then print preview or print the sheet ? Is there any way I can sort the sheet before I print it ?...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
17
by: Philip Wagenaar | last post by:
I have an excel sheet that has several lines. Each line is an order. Example: 1 Paper 10 2 Pencils 20 etc... When the excel sheet is filled out I want the user to press a...
0
by: letsgetsilly | last post by:
I am populating a datagrid and outputting it to excel. Everything worked well last night, but today excel only displays the content in font color white, which is impossible to see. The data is all...
2
by: =?Utf-8?B?UHJpeWE=?= | last post by:
Hi, I'm faced with a classic problem of how to update a large number of records from a web page. I;m trying to build an interface that will display recordset in the order of 3000 rows and allow...
6
by: slinky | last post by:
I found the following code to transfer datagrid data to an Excel file. Is this written in C#?... I'm a vb.netter. I'm just not sure where to place the code to experiment on it. Should I place it in...
1
by: sausthav | last post by:
Hi All, I am unable to get the excel open when user select two dates from my code. Previously i was successfully extracting values by selecting year and month values from the webpage. Could you help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.