If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Getting Recordset Completely in to Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-18-03, 08:27
mtoru mtoru is offline
Registered User
 
Join Date: Sep 2003
Posts: 6
Cool Getting Recordset Completely in to Excel

Hi all,

Is it possible to write all recordset record into an excel sheet ?
I dont want to write it Record by Record with Do While rs.eof..Loop statement because of the long duration while reading record.

Thanks in advance.

Mehmet
Reply With Quote
  #2 (permalink)  
Old 09-19-03, 19:59
rhs98 rhs98 is offline
Super Moderator
 
Join Date: Feb 2002
Location: Hampshire, UK
Posts: 441
There is a command which allows you to specify the format of each row and export a complete recordset as one block. However, it's late and I can't remeber it at this time of night - email, or reply here and I will find it for you in the next couple of days.
Reply With Quote
  #3 (permalink)  
Old 09-20-03, 04:14
mtoru mtoru is offline
Registered User
 
Join Date: Sep 2003
Posts: 6
I will be glad if you post the method that you talked about.

Thanks in advance.
Regards

Mehmet

Quote:
Originally posted by rhs98
There is a command which allows you to specify the format of each row and export a complete recordset as one block. However, it's late and I can't remeber it at this time of night - email, or reply here and I will find it for you in the next couple of days.
Reply With Quote
  #4 (permalink)  
Old 09-21-03, 09:57
fused fused is offline
Registered User
 
Join Date: May 2003
Posts: 23
one way is to output the results to a table. then give that table an id. then use client side script to port that table into excel. i read it in one of the tech articles a few weeks back.

i modified the oringinal scripts to my own needs. Below are my modified version.

Code:
<script language="vbscript">

'***************************************************************************************************************
'This script generates an excel worksheet based on the result shown on the client side. It requires the client '
'to have MS EXCEL installed and ActiveX scripting enabled on the client browser.                               '
'"MyTable" refers to the table ID                                                                              '          
'***************************************************************************************************************

Sub ExportToExcel
On Error Resume Next 'An error will be thrown if ActiveX scripting is disabled.
		Dim objExcel
		Set objExcel = CreateObject("Excel.Application")'Creates the object
		If Len(Err.Description) > 0 Then
			Dim strErrMsg
			strErrMsg = strErrmsg & "An Error has occurred in exporting" & vbCrlF
			strErrMsg = strErrMsg & "Error Description: " & Err.Description & vbCrlf
			strErrMsg = strErrMsg & "Error Number: " & Err.number & vbCRLF
			strErrMsg = strErrMsg & "Please contact System Administrator"
			Msgbox strErrMsg,vbInformation 'contact system admin to enable ActiveX scripting so u can use the feature
			Exit Sub
		End If
		objExcel.Visible = True
		Set objWB = objExcel.Workbooks.Add()
		Set objWS = objWB.Worksheets.Add()
		objWS.Columns(1).ColumnWidth = 25
		objWS.Columns(2).ColumnWidth = 15
		Dim MyRow, MyCell
		RowCount = 0 
		For Each MyRow in MyTable.rows
		i=i+1
			If i Mod 2 = 0 Then 'Alternate rowcolor..white
				RowCount = RowCount + 1 
				ColCount = 0
				For Each MyCell In MyRow.Cells
					ColCount = ColCount + 1
					If Trim(MyCell.InnerText) = "" Then
						MyValue = ""
					Else
						MyValue = MyCell.InnerText
					End If
					objWS.Cells(RowCount,ColCount) = MyValue
					If RowCount = 1 Then
						objWS.Cells(RowCount,ColCount).Font.Bold = True
						objWS.Cells(RowCount,ColCount).HorizontalAlignment = 1
						objWS.Cells(RowCount,ColCount).Interior.Color = RGB(192,192,192)			
					End If
				Next
			Else'Alternate rowcolor..grey
				RowCount = RowCount + 1 
				ColCount = 0
				objExcel.rows(rowCount).Interior.Color = RGB(192,192,192)
				For Each MyCell In MyRow.Cells
					ColCount = ColCount + 1
					If Trim(MyCell.InnerText) = "" Then
						MyValue = ""
					Else
						MyValue = MyCell.InnerText
					End If
					objWS.Cells(RowCount,ColCount) = Trim(MyValue)
					If RowCount = 1 Then
						objWS.Cells(RowCount,ColCount).Font.Bold = True
						objWS.Cells(RowCount,ColCount).HorizontalAlignment = 1
						objWS.Cells(RowCount,ColCount).Interior.Color = RGB(192,192,192)			
					End If
				Next
			End If
		Next
		objExcel.Cells.Select
		objExcel.Cells.Font.Name = "Arial"
		objExcel.Cells.Font.Size = 8
		objWS.Range("A1",Chr(ColCount + 64) & RowCount).Columns.Autofit
		objExcel.Selection.HorizontalAlignment = &hFFFFEFDD 'Align Left
		Set objWB = Nothing		'Cleaning up
		Set objWS = Nothing		'Cleaning up
		Set objExcel = Nothing  'Cleaning up
End Sub
</script>
Reply With Quote
  #5 (permalink)  
Old 02-09-04, 06:41
Mirador Mirador is offline
Registered User
 
Join Date: Jan 2004
Location: Oslo
Posts: 45
Hi Fused...

Hope you can read this post..

What i wonder is if the code u've posted requires Excel to be installed on the server ? And.. will it produce much traffic if many people is gonna use this ?

I got this code which i'm using to display all content to html table..
How can i use my code included in the one you posted ?
(PS!.. How can i use a Array for the same thing?)

--------------------CODE------------------------
For intRad = 0 to intSisteRad
Response.Write "<tr class ='litentekst' bgcolor='#F5F5F5'>"
For intKolonne = 0 to intSisteKolonne
Response.write "<td height='35'>" & varArray(intKolonne,intRad) & "</td>"
next
Response.write "<td><center><input type='text' name='txtMerknad' size='40' border='0'></center></td>"
Response.Write "</tr>"
Next
---------------------END-------------------------

Quote:
Originally posted by fused
one way is to output the results to a table. then give that table an id. then use client side script to port that table into excel. i read it in one of the tech articles a few weeks back.

i modified the oringinal scripts to my own needs. Below are my modified version.

Code:
<script language="vbscript">

'***************************************************************************************************************
'This script generates an excel worksheet based on the result shown on the client side. It requires the client '
'to have MS EXCEL installed and ActiveX scripting enabled on the client browser.                               '
'"MyTable" refers to the table ID                                                                              '          
'***************************************************************************************************************

Sub ExportToExcel
On Error Resume Next 'An error will be thrown if ActiveX scripting is disabled.
		Dim objExcel
		Set objExcel = CreateObject("Excel.Application")'Creates the object
		If Len(Err.Description) > 0 Then
			Dim strErrMsg
			strErrMsg = strErrmsg & "An Error has occurred in exporting" & vbCrlF
			strErrMsg = strErrMsg & "Error Description: " & Err.Description & vbCrlf
			strErrMsg = strErrMsg & "Error Number: " & Err.number & vbCRLF
			strErrMsg = strErrMsg & "Please contact System Administrator"
			Msgbox strErrMsg,vbInformation 'contact system admin to enable ActiveX scripting so u can use the feature
			Exit Sub
		End If
		objExcel.Visible = True
		Set objWB = objExcel.Workbooks.Add()
		Set objWS = objWB.Worksheets.Add()
		objWS.Columns(1).ColumnWidth = 25
		objWS.Columns(2).ColumnWidth = 15
		Dim MyRow, MyCell
		RowCount = 0 
		For Each MyRow in MyTable.rows
		i=i+1
			If i Mod 2 = 0 Then 'Alternate rowcolor..white
				RowCount = RowCount + 1 
				ColCount = 0
				For Each MyCell In MyRow.Cells
					ColCount = ColCount + 1
					If Trim(MyCell.InnerText) = "" Then
						MyValue = ""
					Else
						MyValue = MyCell.InnerText
					End If
					objWS.Cells(RowCount,ColCount) = MyValue
					If RowCount = 1 Then
						objWS.Cells(RowCount,ColCount).Font.Bold = True
						objWS.Cells(RowCount,ColCount).HorizontalAlignment = 1
						objWS.Cells(RowCount,ColCount).Interior.Color = RGB(192,192,192)			
					End If
				Next
			Else'Alternate rowcolor..grey
				RowCount = RowCount + 1 
				ColCount = 0
				objExcel.rows(rowCount).Interior.Color = RGB(192,192,192)
				For Each MyCell In MyRow.Cells
					ColCount = ColCount + 1
					If Trim(MyCell.InnerText) = "" Then
						MyValue = ""
					Else
						MyValue = MyCell.InnerText
					End If
					objWS.Cells(RowCount,ColCount) = Trim(MyValue)
					If RowCount = 1 Then
						objWS.Cells(RowCount,ColCount).Font.Bold = True
						objWS.Cells(RowCount,ColCount).HorizontalAlignment = 1
						objWS.Cells(RowCount,ColCount).Interior.Color = RGB(192,192,192)			
					End If
				Next
			End If
		Next
		objExcel.Cells.Select
		objExcel.Cells.Font.Name = "Arial"
		objExcel.Cells.Font.Size = 8
		objWS.Range("A1",Chr(ColCount + 64) & RowCount).Columns.Autofit
		objExcel.Selection.HorizontalAlignment = &hFFFFEFDD 'Align Left
		Set objWB = Nothing		'Cleaning up
		Set objWS = Nothing		'Cleaning up
		Set objExcel = Nothing  'Cleaning up
End Sub
</script>
__________________
Best regards
Mirador

Last edited by Mirador; 02-09-04 at 06:43.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On