Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel automatic saving

Status
Not open for further replies.

ching0418

MIS
Mar 6, 2002
96
0
0
HK
Hi,

I have a page which creates an excel file. I receive a prompt if i want to save the file and to specify the location where the file should be saved.

I want to eliminate the prompt. i want my ASP page to automatically save it to a specified location without any user intervention. how can i do that?

thanks in advance!
 
And if you are trying to store it client side then you should generate the excel file client side and save it but that requires using ActiveX to access the client side app which means you are limited to IE browsers and the client will receive an ActiveX warning prompt before the code can execute.

There is no way to automatically copy the excel file from the server to the client's PC without some form of response required on the client side, otherwise anybody could populate your computer with whatever files they wanted to including replacing important files with trojans.


Paranoid? ME?? WHO WANTS TO KNOW????
 
hello,

i used the following code to generate the excel file:

Code:
<!--#include file="Connections/infosys.asp" -->
<!--#include file="include/getvars.asp"-->	
<%
Dim rsFU
Dim rsFU_numRows

Set rsFU = Server.CreateObject("ADODB.Recordset")
rsFU.ActiveConnection = MM_infosys_STRING
rsFU.Source = "SELECT * FROM dbo.TMDFU where login = '" & request("login") & "' and ponum = '" & request("ponum") & "' order by typct"
rsFU.CursorType = 0
rsFU.CursorLocation = 2
rsFU.LockType = 1
rsFU.Open()

rsFU_numRows = 0
%>
<%	Response.ContentType="application/vnd.ms-excel"
    Response.AddHeader "Content-Disposition", "filename=D:\pomails\" & request("ponum") & ".xls;"%>
<%

response.Write("<table>")
response.Write("<tr>")
response.Write("<td>PO NUMBER</td>")
response.Write("<td>""" & request("ponum") & """</td>")
response.Write("</tr>")
response.Write("<tr>")
response.Write("<td>SUPPLIER</td>")
response.Write("<td>" & request("supno") & "</td>")
response.Write("<td colspan=8>" & request("sunam") & "</td>")
response.Write("</tr>")
response.Write("<tr>")
response.Write("<td>SHIPPED DATE</td>")
response.Write("<td>" & request("sdate") & "</td>")
response.Write("<td></td>")
response.Write("<td>AMOUNT</td>")
response.Write("<td>" & request("crncy") & " " & request("amount") & "</td>")
response.Write("</tr>")
response.Write("<tr>")
response.Write("</tr>")
response.Write("<tr>")
response.Write("<td>Document</td>")
response.Write("<td>1st Follow-up</td>")
response.Write("<td>1st Reply</td>")
response.Write("<td>2nd Follow-up</td>")
response.Write("<td>2nd Reply</td>")
response.Write("<td>3rd Follow-up</td>")
response.Write("<td>3rd Reply</td>")
response.Write("<td>4th Follow-up</td>")
response.Write("<td>4th Reply</td>")
response.Write("<td>OK Date</td>")
response.Write("</tr>")

do while not rsfu.eof
	response.Write("<tr>")
	response.Write("<td font-weight:bold>" & rsfu("typec") & "</td>")
	if rsfu("flwup1")="1/1/1900" then response.Write("<td></td>") else response.Write("<td>" & rsfu("flwup1") & "</td>")
	if rsfu("reply1")="1/1/1900" then response.Write("<td></td>") else response.Write("<td>" & rsfu("reply1") & "</td>")
	if rsfu("flwup2")="1/1/1900" then response.Write("<td></td>") else response.Write("<td>" & rsfu("flwup2") & "</td>")
	if rsfu("reply2")="1/1/1900" then response.Write("<td></td>") else response.Write("<td>" & rsfu("reply2") & "</td>")
	if rsfu("flwup3")="1/1/1900" then response.Write("<td></td>") else response.Write("<td>" & rsfu("flwup3") & "</td>")
	if rsfu("reply3")="1/1/1900" then response.Write("<td></td>") else response.Write("<td>" & rsfu("reply3") & "</td>")
	if rsfu("flwup4")="1/1/1900" then response.Write("<td></td>") else response.Write("<td>" & rsfu("flwup4") & "</td>")
	if rsfu("reply4")="1/1/1900" then response.Write("<td></td>") else response.Write("<td>" & rsfu("reply4") & "</td>")
	if rsfu("okdte")="1/1/1900" then response.Write("<td></td>") else response.Write("<td>" & rsfu("okdte") & "</td>")
	response.Write("</tr>")
	response.Write("<tr>")
	response.Write("<td>1st Follow-up Remark</td>")
	response.Write("<td colspan=9>" & rsfu("rmrks1") & "</td>")
	response.Write("</tr>")
	response.Write("<tr>")
	response.Write("<td>2nd Follow-up Remark</td>")
	response.Write("<td colspan=9>" & rsfu("rmrks2") & "</td>")
	response.Write("</tr>")
	response.Write("<tr>")
	response.Write("<td>3rd Follow-up Remark</td>")
	response.Write("<td colspan=9>" & rsfu("rmrks3") & "</td>")
	response.Write("</tr>")
	response.Write("<tr>")
	response.Write("<td font-size:8pt align=right>4th Follow-up Remark</td>")
	response.Write("<td colspan=9>" & rsfu("rmrks4") & "</td>")
	response.Write("</tr>")
	rsfu.movenext
loop

response.Write("</table>")
%>
<%
Set Mail=Server.CreateObject("Persits.MailSender")

Mail.Host = "192.168.54.23"
Mail.Port = 25

Mail.From = "mail@mail.com"
Mail.FromName = "Mailman"

Mail.AddAddress "mail@mail.com"

Mail.Subject = "Test Mail"

Mail.Body = "This is a test mail.  Please ignore!"

Mail.AddAttachment "D:\pomails\" & request("ponum") & ".xls"

on error resume next

Mail.Send

Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile "D:\pomails\" & request("ponum") & ".xls"

set fso=nothing

rsFU.Close()
Set rsFU = Nothing

If Err <> 0 Then
	Response.Write("An error occured: " & Err.Description)
end if
%>

I am successful in creating the excel file. But during the first run, it can't send the mail because there's an error:
An error occured: The system cannot find the file specified.

But the file is there. And on the second run, a mail will be sent, but sending the previous file that should be sent during the first run. Why is that happening?
 
Are you using your own PC as the web server to test this?
You are giving a literal path to the file including a drive name. I suspect you are writing the file client-side, not server-side.
You are certainly trying to delete the file client-side because you use CreateObject rather than Server.CreateObject when you go to delete the file.

But when you go to email the file you use Server.CreateObject so it is looking on the server for the file rather than the local drive which is where I suspect the file was written so it is unavailable to the server to get and email the file.



Paranoid? ME?? WHO WANTS TO KNOW????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top