I can't see how to implement (adoCon is a connection to your excel file
through ADO, rsExcel is a
recordset) with my current code.
I'm using this include file to get my data connection:
function GetDataConnection()
dim oConn, strConn
Set oConn = Server.CreateObject("ADODB.Connection")
strConn = "Provider=SQLOLEDB; Data Source=SQL; Initial
Catalog=ITDatabase; "
strConn = strConn & "Persist Security Info=True; User Id=sa;
Password=s4x399k;"
oConn.Open strConn
set GetDataConnection = oConn
end function
Then, using this in the CreateXlsFile function that follows (excerpt
from further below):
Set objConn = GetDataConnection
sqlString = "SELECT * FROM TEMP_TABLE ORDER BY requestId ASC"
Set RS = objConn.Execute(sqlString)
Here is the CreateXlsFile function:
Function CreateXlsFile()
Dim xlWorkSheet
Dim xlApplication, objConn
Set xlApplication = Server.CreateObject("Excel.Application")
xlApplication.Visible = False
xlApplication.Workbooks.Add
Set xlWorksheet = xlApplication.Worksheets(1)
response.write("<font face=""Arial""l"" size=""1"">Please Note: " &
"<br>" & vbCr)
response.write("You can copy and paste into an Excel worksheet or
save as an Excel (.xls) file. " & "<br>" & vbCr)
response.write("The file will be assigned a file name, but you can
change it. You must choose a directory " & "<br>" & vbCr)
response.write("on your local (C

drive to save the file to
(File/Save as/Save in), otherwise you will get a ""trying to save a
read-only"" file error. " & "</font><br><br>" & vbCr)
xlWorksheet.Cells(1,1).Value = "Request ID"
xlWorksheet.Cells(1,2).Value = "Date Requested"
xlWorksheet.Cells(1,3).Value = "Requestor Name"
xlWorksheet.Cells(1,4).Value = "Requestor's Dept"
xlWorksheet.Cells(1,5).Value = "Request Type"
xlWorksheet.Cells(1,6).Value = "TempModule"
xlWorksheet.Cells(1,7).Value = "Priority"
xlWorksheet.Cells(1,8).Value = "High Priority Reason"
xlWorksheet.Cells(1,9).Value = "Final Priority"
xlWorksheet.Cells(1,10).Value = "Time Cost Savings"
xlWorksheet.Cells(1,11).Value = "Request Desc"
xlWorksheet.Cells(1,12).Value = "Request Reason"
xlWorksheet.Cells(1,13).Value = "Upload File"
xlWorksheet.Cells(1,14).Value = "Assigned To"
xlWorksheet.Cells(1,15).Value = "Assigned Date"
xlWorksheet.Cells(1,16).Value = "Status"
xlWorksheet.Cells(1,17).Value = "Reviewed/Declined By"
xlWorksheet.Cells(1,18).Value = "Reviewed/Declined Date"
xlWorksheet.Cells(1,19).Value = "Time To Complete"
xlWorksheet.Cells(1,20).Value = "Completion Date"
xlWorksheet.Cells(1,21).Value = "Active/Inactive"
for index = 1 to 22
xlWorksheet.Cells(1,index).Interior.ColorIndex = 0
next
' iRow = 2
Set objConn = GetDataConnection
sqlString = "SELECT * FROM TEMP_TABLE ORDER BY requestId ASC"
Set RS = objConn.Execute(sqlString)
If Not RS.Eof Then
iRow = 2
Do Until RS.Eof
xlWorksheet.Cells(iRow, 1).Value = RS("requestId")
dateArray = split(RS("Date_Requested"), vbCrLf, -1 ,1)
xlWorksheet.Cells(iRow, 2).Value = dateArray(0)
xlWorksheet.Cells(iRow, 3).Value = RS("Requestor_Name")
xlWorksheet.Cells(iRow, 4).Value = RS("Department")
xlWorksheet.Cells(iRow, 5).Value = RS("Recommendation_Type")
xlWorksheet.Cells(iRow, 6).Value = RS("TEMP_Module")
xlWorksheet.Cells(iRow, 7).Value = RS("Priority")
xlWorksheet.Cells(iRow, 8).Value = RS("High_Priority_Reason")
xlWorksheet.Cells(iRow, 9).Value = RS("Final_Priority")
xlWorksheet.Cells(iRow, 10).Value = RS("Time_Cost_Savings")
xlWorksheet.Cells(iRow, 11).Value = RS("Recommendation_Desc")
xlWorksheet.Cells(iRow, 12).Value = RS("Recommendation_Reason")
If RS("Upload_File") <> "\\temp_2\wwwroot\fupload\Upload\" Then
xlWorksheet.Cells(iRow, 13).Value = RS("Upload_File")
Else
xlWorksheet.Cells(iRow, 13).Value = ""
End If
xlWorksheet.Cells(iRow, 14).Value = RS("Assigned_To")
If xlWorksheet.Cells(iRow, 15).Value = RS("Assigned_Date") <> ""
Then
dateArray = split(RS("Assigned_Date"), vbCrLf, -1 ,1)
xlWorksheet.Cells(iRow, 15).Value = dateArray(0)
Else
xlWorksheet.Cells(iRow, 15).Value = ""
End If
xlWorksheet.Cells(iRow, 16).Value = RS("Status")
xlWorksheet.Cells(iRow, 17).Value = RS("Reviewed_By")
If xlWorksheet.Cells(iRow, 18).Value = RS("Reviewed_Date") <> ""
Then
dateArray = split(RS("Reviewed_Date"), vbCrLf, -1 ,1)
xlWorksheet.Cells(iRow, 18).Value = dateArray(0)
Else
xlWorksheet.Cells(iRow, 18).Value = ""
End If
xlWorksheet.Cells(iRow, 19).Value = RS("Time_To_Complete")
If xlWorksheet.Cells(iRow, 20).Value = RS("Completion_Date") <> ""
Then
dateArray = split(RS("Completion_Date"), vbCrLf, -1 ,1)
xlWorksheet.Cells(iRow, 20).Value = dateArray(0)
Else
xlWorksheet.Cells(iRow, 20).Value = ""
End If
xlWorksheet.Cells(iRow, 21).Value = RS("Active_Inactive")
iRow = iRow + 1
RS.MoveNext
Loop
erase dateArray
End If
strFile = GenFileName(fname)
RS.Close
objConn.Close
Set objConn = Nothing
strFile = GenFileName(fname)
'This folder needs to be created on the server:
xlWorksheet.SaveAs Server.MapPath(".") & "\TempRequestDownload\" &
strFile & ".xls"
' "C:\Inetpub\wwwroot\RecommendationForm\ExcelDownload\" & strFile
xlApplication.Quit
' Close the Workbook
Set xlWorksheet = Nothing
Set xlApplication = Nothing
Response.Write("<font face=""Arial""l"" size=""1"">Click <a
href=TempRequestDownload\" & strFile & ".xls TARGET='_blank'>HERE</A>
to get Excel file</font><br>" & vbCr)
'response.write("after: " & now() & "<br>" & vbCr)
End Function
%>
Thanks,
MC/KP