I have a search page in my program where users can search for member data. The results come up in the data grid view, but I also want users to be able to export the search results into an Excel spreadsheet. What is the best way to do this?
2 2193
Here is my VB6 function where I can pass highlited part of a grid or whole thing to Excel. - Public Function SaveFlexGridToExcel(TheFlexgrid As MSFlexGrid, _
-
TheRows As Integer, TheCols As Integer, _
-
Optional GridStyle As Integer = 1, Optional WorkSheetName As String)
-
-
Dim objXL 'As New Excel.Application
-
Dim wbXL 'As New Excel.Workbook
-
Dim wsXL 'As New Excel.Worksheet
-
Dim intRow As Integer ' counter
-
Dim intCol As Integer ' counter
-
-
On Error GoTo ErrorHandler
-
-
Set objXL = CreateObject("Excel.Application.11")
-
-
If Not IsObject(objXL) Then
-
MsgBox "You need Microsoft Excel to use this function", _
-
vbExclamation, "Print to Excel"
-
Exit Function
-
End If
-
-
' open Excel
-
objXL.Visible = True
-
Set wbXL = objXL.Workbooks.Add
-
Set wsXL = objXL.ActiveSheet
-
-
' name the worksheet
-
If Not WorkSheetName = "" Then wsXL.Name = WorkSheetName
-
-
' fill worksheet
-
'Skip first column
-
For intRow = 1 To TheRows
-
For intCol = 2 To TheCols
-
With TheFlexgrid
-
wsXL.Cells(intRow, intCol - 1).Value = .TextMatrix(intRow - 1, intCol - 1) & " "
-
End With
-
Next
-
Next
-
-
' format the look
-
For intCol = 1 To TheCols
-
wsXL.Columns(intCol).AutoFit
-
'wsXL.Columns(intCol).AutoFormat (1)
-
Next
-
-
'wsXL.Range("a1", Right(wsXL.Columns(TheCols).AddressLocal, 1) & TheRows).AutoFormat GridStyle
-
-
Set objXL = Nothing
-
Screen.MousePointer = vbNormal
-
-
Exit Function
-
ErrorHandler:
-
MsgBox Err.Description, vbOKOnly + vbExclamation, " [SaveFlexGridToExcel]"
-
End Function
Hope it helps.
Good Luck.
Here is my VB6 function where I can pass highlited part of a grid or whole thing to Excel. - Public Function SaveFlexGridToExcel(TheFlexgrid As MSFlexGrid, _
-
TheRows As Integer, TheCols As Integer, _
-
Optional GridStyle As Integer = 1, Optional WorkSheetName As String)
-
-
Dim objXL 'As New Excel.Application
-
Dim wbXL 'As New Excel.Workbook
-
Dim wsXL 'As New Excel.Worksheet
-
Dim intRow As Integer ' counter
-
Dim intCol As Integer ' counter
-
-
On Error GoTo ErrorHandler
-
-
Set objXL = CreateObject("Excel.Application.11")
-
-
If Not IsObject(objXL) Then
-
MsgBox "You need Microsoft Excel to use this function", _
-
vbExclamation, "Print to Excel"
-
Exit Function
-
End If
-
-
' open Excel
-
objXL.Visible = True
-
Set wbXL = objXL.Workbooks.Add
-
Set wsXL = objXL.ActiveSheet
-
-
' name the worksheet
-
If Not WorkSheetName = "" Then wsXL.Name = WorkSheetName
-
-
' fill worksheet
-
'Skip first column
-
For intRow = 1 To TheRows
-
For intCol = 2 To TheCols
-
With TheFlexgrid
-
wsXL.Cells(intRow, intCol - 1).Value = .TextMatrix(intRow - 1, intCol - 1) & " "
-
End With
-
Next
-
Next
-
-
' format the look
-
For intCol = 1 To TheCols
-
wsXL.Columns(intCol).AutoFit
-
'wsXL.Columns(intCol).AutoFormat (1)
-
Next
-
-
'wsXL.Range("a1", Right(wsXL.Columns(TheCols).AddressLocal, 1) & TheRows).AutoFormat GridStyle
-
-
Set objXL = Nothing
-
Screen.MousePointer = vbNormal
-
-
Exit Function
-
ErrorHandler:
-
MsgBox Err.Description, vbOKOnly + vbExclamation, " [SaveFlexGridToExcel]"
-
End Function
Hope it helps.
Good Luck.
Do you have anything in C#??
Sign in to post your reply or Sign up for a free account.
Similar topics
by: cpeters5 |
last post by:
Deaa group,
I am using SQLServer 2000 in an XP Sp2. I would like to do the
following:
I have a program running on a database server that generates some data
which are loaded to the database....
|
by: Jason |
last post by:
Can anyone point me to some sample code or tutorial that shows how I can
export data from a database to an Excel spreadsheet that is already created
on the server?
I have an Excel spreadsheet...
|
by: Gary Wright |
last post by:
I have an Access 2K database split into front and back. Quite often the
users want to do some data analysis that I have not created a report for so
they want to export some subset of the data into...
|
by: OptikConnex |
last post by:
I have data that I need to either put in a spreadsheet, or use in a listview to view it. I would rather use the listview but I don't understand how to put my data into it. Here is the code I have,...
|
by: Scott M. Lyon |
last post by:
I'm trying to figure out a way to export data (actually the result of a
Stored Procedure call from SQL Server) into a specified Excel spreadsheet
format.
Currently, I have the data read into a...
|
by: JLuv |
last post by:
What i want to do is take the checked data from a datagrid, send it to
a table, then show that table on an Excel Spreadsheet. Here is a little
bit of my code...
//adminProgress.aspx...
|
by: nofear |
last post by:
I used to export my reports as snapshot but now I have to export them
to Excel
When I export my report to a Excel Spreadsheet the report header and
footer are not included
Only the data gets...
|
by: yovation |
last post by:
Hi,
I have a 3 table database.
1 parent
1 child
1 child of child
I would like to get the data into excel as 1 sheet (similar to a
grouped report).
|
by: =?Utf-8?B?RXJpayBLLiBTY2hpbmRlbGRlY2tlcg==?= |
last post by:
Good Afternoon,
I am trying to programmatically define our company logo in the header of a
..Net Export to Excel spreadsheet. I have tried to find some type of MetaData
associated with...
|
by: Stephen Wallace |
last post by:
Hi experts,
i want to know what's the best way to export data from spreadsheet to datatable? maybe, any way that can export data from spreadsheet to datatable.
Thanks for any answers.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |