Forum Moderators: open

Message Too Old, No Replies

exporting an ASP file to Microsoft Word

exporting an ASP file to Microsoft Word

         

Ecstacy

12:44 pm on Aug 15, 2003 (gmt 0)

10+ Year Member



Hi,

I am developing a site in ASP.

There I am showing a report. Now, I want to export this report to word so that the user can save it on his machine and can modify accordingly.

If anyone know this then please help me out.

- Ecstacy

skipfactor

12:51 pm on Aug 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With IE6 and Office XP installed, you can open the page in IE6 by choosing, "File", "Edit w/ MS Word". Then save it as a doc in Word. Not sure if this works in previous versions of Office or IE.

richardb

1:02 pm on Aug 15, 2003 (gmt 0)

10+ Year Member



Hi we had a look at excell in this thread, however the same principles would apply.

[webmasterworld.com...]

Rich

txbakers

1:18 pm on Aug 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using ASP you can open Excel and populate rows and columns automatically from the database.

I offer my users the ability to download the data from their files directly to excel - works great.

I can post a link to the code if you like.

skipfactor

1:24 pm on Aug 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd like to have a look txbakers. :)

txbakers

2:47 pm on Aug 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Rather than break the TOS and post a link, here is sample of the code to do this:

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=nothing

Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Application.Visible = True
Set ExcelBook = ExcelApp.Workbooks.Add

ExcelBook.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.EOF

ExcelBook.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 = nothing

ExcelBook.SaveAs "E:\files\library.xls"

ExcelApp.Application.Quit
Set ExcelApp = Nothing

Response.Redirect("files\library.xls")

aspdaddy

10:30 pm on Aug 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>Set ExcelApp = CreateObject("Excel.Application")

It is very handy code, butI wouldnt reccomend doing this on a busy web server. You could ouptut .csv for this and let them open Excel :)

>modify accordingly

What kind of things do they need to do?

RossWal

11:48 pm on Aug 15, 2003 (gmt 0)

10+ Year Member



txbakers,
Are you running excel 2003? I was researching this last week and read some stuff on msdn where they (I think) strongly recommended against this in excel 2000. IIRC, the issue was that excel 2000 assumes a visual interface and could try to pop-up visual dialogs that would hang the server.

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

aspdaddy

12:51 am on Aug 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I *think* you can install the OWC.Chart component, without having office applications installed.

txbakers

3:41 am on Aug 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm running Excel 2000. But now that I think about - I will rewrite the entire thing to produce a text/csv file instead. I don't need hundreds of people creating Excel apps on my server at the same time. That would be a big CPU drain for sure.

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.....

Ecstacy

9:28 am on Aug 16, 2003 (gmt 0)

10+ Year Member



Thanks a lot all of you for your precious advice.

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.

aspdaddy

9:47 am on Aug 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like Excel is not installed on the server.

txbakers

6:25 pm on Aug 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Exactly - the only way to create an Excel app, is to have Excel installed on the server.

If not, you will have to make a text file and name it XXX.csv, which will default to open in Excel.

Making a text file involves different code than above.