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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGETNT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Status
Not open for further replies.

ramnagar

Programmer
Apr 25, 2002
22
US
I would like to export ASP page output to word document . when i use
Response.ContentType = "application/msword"
The page DOES load as a Word document, but no values from the recordset on the page, rather it is showing html source code . Can any body help me how to export to word document from ASP page?...

Thanks in Advance,
Rama Krishna.B
 
Hi there

When I run a report through asp I actually export to a PDF File, but I have allowed for other file types (such as word to be used. I set up my report with an openreport function then I called a Function called DisplayReport which looks like this:

I hope this helps!!!


Function DisplayReport(oRpt,FileType,blnForDownload)

Dim strDocumentName, strExt, strPath,iLen

'Set Format type and ext.
With oRpt.ExportOptions
Select Case FileType
Case crMSWord
.FormatType = 14
strExt = ".doc"
Response.ContentType = "application/msword"
Case crMSExcel
.FormatType = 21
strExt = ".xls"
Response.ContentType = "application/vnd.ms-excel"
Case crMSExcelTab
.FormatType = 22
strExt = ".xls"
Response.ContentType = "application/vnd.ms-excel"
Case crHTML
.FormatType = 24
strExt = ".html"
Response.ContentType = "text/html"
Case crPText
.FormatType = 10
strExt = ".doc"
Response.ContentType = "application/msword"
Case crRTF
.FormatType = 4
strExt = ".rtf"
If blnForDownload Then
Response.ContentType = "text/richtext"
Else
Response.ContentType = "application/msword"
End If
Case crTXT
.FormatType = 8
strExt = ".txt"
If blnForDownload Then
Response.ContentType = "text/plain"
Else
Response.ContentType = "text/html"
End If
Case crTAB
.FormatType = 6
strExt = ".csv"
If blnForDownload Then
Response.ContentType = "text/plain"
Else
Response.ContentType = "application/vnd.ms-excel"
End If
Case crCSV
.FormatType = 5
strExt = ".csv"
If blnForDownload Then
Response.ContentType = "text/plain"
Else
Response.ContentType = "application/vnd.ms-excel"
End If
Case crPDF
.FormatType = 31
strExt = ".pdf"
Response.ContentType = "application/pdf"
Case Else
.FormatType = 31
strExt = ".pdf"
Response.ContentType = "application/pdf"
End Select

strPath = Request.ServerVariables("PATH_TRANSLATED")
While (Right(strPath, 1) <> &quot;\&quot; And Len(strPath) <> 0)
iLen = Len(strPath) - 1
strPath = Left(strPath, iLen)
Wend

strDocumentName = Year(Date) & Month(Date) & Day(Date) & Hour(Time) & Minute(Time) & Second(Time) & strExt
strPath = strPath & strDocumentName
.DestinationType = 1
.DiskFileName = strPath
End With

oRpt.Export False

Set oRpt = Nothing

' download file
Dim str
set str = createobject(&quot;ADODB.Stream&quot;)
str.type = 1
str.open
str.LoadFromFile strPath
If blnForDownload Then
Response.Addheader &quot;Content-Disposition&quot;, &quot;attachment;filename=&quot; & strDocumentName
End IF
Response.BinaryWrite str.Read

set str = nothing

Dim FSO
Set FSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

If FSO.FileExists(strPath) Then
FSO.DeleteFile(strPath)
End If

Set FSO = Nothing
End Function

Transcend

 
Hi,
Thanks for your reply. Could you please give your complete code because i dont know when i have to call this function either at the begining of the asp page or at the end.

for ex:

<%
dim Ram
ram=&quot; hello&quot;

response.write ram


%>

suppose if i want to export the output (here &quot;hello&quot;) to word document where i have to place your code?..

Thanks In advance,

Rama Krishna.B
 
I have to export the data into a file and it should be saved on clients desktop. Can you please tell me how to do it?..
 
If the page opens in the Browser via MS Word the user can save the document to his desktop using the Save As feature of the browser.
Thanks,

Gabe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top