Forum Moderators: open
[webmasterworld.com...]
Rich
What this code does is create the FSO, then checks to see if the object exists, if so, then delete it.
Next, it creates an Excel App and adds a workbook to it. I set the first row's properties and headers, then open a record set to get the data. I populate the rows in a DO-WHILE loop, save the spreadsheet when EOF, then redirect the user to that file. If they can see XLS in a browser it opens automatically, if not, they are asked to download it.
Works very well - never had a problem. (Except for large files it takes some time and I thought I crashed my browser!)
dim fs
Set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.FileExists("E:\files\library.xls") = true then
fs.DeleteFile "E:\files\library.xls",true
end if
set fs=nothingSet ExcelApp = CreateObject("Excel.Application")
ExcelApp.Application.Visible = True
Set ExcelBook = ExcelApp.Workbooks.AddExcelBook.Worksheets(1).Cells(1, 1).Font.Size = 9
ExcelBook.Worksheets(1).Cells(1, 1).Font.Bold = true
ExcelBook.Worksheets(1).Cells(1, 1).Value="Category"
ExcelBook.Worksheets(1).Cells(1, 2).Font.Size = 9
ExcelBook.Worksheets(1).Cells(1, 2).Font.Bold = true
ExcelBook.Worksheets(1).Cells(1, 2).Value="Title"
ExcelBook.Worksheets(1).Cells(1, 3).Font.Size = 9
ExcelBook.Worksheets(1).Cells(1, 3).Font.Bold = true
ExcelBook.Worksheets(1).Cells(1, 3).Value="Composer"set rsLib = Server.CreateObject("ADODB.RecordSet")
rsLib.Open "SELECT title,comp,arrang,category,insttype,libnum,numcop,publisher,comments FROM library where schcode ='" & Session("Schoolcode") & "' order by category,comp, title", ConnSQL, 1, 3
dim i
i = 2
Do while NOT rsLib.EOFExcelBook.Worksheets(1).Cells(i, 1).Value=RSLib("category")
ExcelBook.Worksheets(1).Cells(i, 2).Value=RSLib("title")
ExcelBook.Worksheets(1).Cells(i, 3).Value=RSLib("comp")RSLib.movenext
i = i + 1
Loop
RSLib.close
set rsEvent = nothingExcelBook.SaveAs "E:\files\library.xls"
ExcelApp.Application.Quit
Set ExcelApp = NothingResponse.Redirect("files\library.xls")
Also, what about when the xls is the source on the webserver. Anyway to generate graphs to display in the html sent to the client?
Thanks all!
Ross
I'm not sure what happens when we link to a CSV - does it open in Excel automatically or will it ask to download?
I'll have to find out.....
I have implemented the code given by "txbakers".
Now after implementing it on one page the page gives the following error.
-------------------------------------------------
Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object: 'Excel.Application'
/soup/code/admin/export_excel.asp, line 9
-------------------------------------------------
Can anyone give me solution to this problem.