We help IT Professionals succeed at work.

Open Excel and powerpoint document.

aspnewbie
aspnewbie asked
on
Medium Priority
968 Views
Last Modified: 2012-08-13
how to open excel and powerpoint document?? and save it as .html
Comment
Watch Question

Michel SakrRounded IT Consultant / Projects manager / Cloud Consultant / IT Planning
CERTIFIED EXPERT

Commented:
you can't alas upload folders.. you'll have to upload them file by file (or by group using several file inputs) besides the asp code should be developed in a way to let the user also create a directory on the server for your purpose.. this can be done using FSO also:

some FSO examples below:

<%

' create the fso object

set fso = Server.Createobject("Scripting.FileSystemObject")

path = "c:\temp\test.txt"

strDate = Replace(Date(), "/", "")

strDir = "c:\inetpub\wwwroot\articles\" & strDate

strNewFileName = Hour(Now) & "_" & Minute(Now) & "_" & second(Now) & ".html"



' open the old file

set file = fso.opentextfile(path, 1)  <-- For reading

strText = file.readall

set file = nothing



' check for and/or create folder

if not fso.folderexists(Server.MapPath(strDir)) then

     set f = fso.CreateFolder(Server.MapPath(strDir))

else

     set f = fso.GetFolder(Server.MapPath(strDir))

end if



' create and write new file

set file = fso.Createtextfile(f.path & "\" & strNewFileName)

file.write(strText)

set f = nothing

file.close

set file = nothing



' delete the old file

fso.DeleteFile(path & "\" & rst("FileName") & i)



' clean up

set fso = nothing

%>

also check these links for more:
http://www.4guysfromrolla.com/webtech/090599-1.shtml
http://www.15seconds.com/Issue/000816.htm
http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbenlr98/vaobjfilesystemobject.htm 
Michel SakrRounded IT Consultant / Projects manager / Cloud Consultant / IT Planning
CERTIFIED EXPERT

Commented:
I recall noe that asp upload now has this feature:

http://www.aspupload.com/about.html
Michel SakrRounded IT Consultant / Projects manager / Cloud Consultant / IT Planning
CERTIFIED EXPERT

Commented:
but it seems it needs an activex to be set on the client..

Author

Commented:
since there is no solution for this, i will change the topic to:

In word to open document using this component

set wrd =CreateObject("Word.Application")

then what about in excel and powerpoint?? I need it to open and then save as .html format


thank you
aspnewbie
Michel SakrRounded IT Consultant / Projects manager / Cloud Consultant / IT Planning
CERTIFIED EXPERT

Commented:
Ehh.. EE policies forbid the renaming of already answered questions.. but anyways I'll try to help you in the second question..


Dynamic excel example:
http://www.aspalliance.com/stevesmith/articles/exceltutorial.asp

More codes:
http://www.aspin.com/home/tutorial/document/xls


now I guess you want to flush the documents in the browser context to the client then try:

you'll need to send the file content in a stream.. if the client has the appropriate application installed
then it'll open in the browser, otherwise the user will get a save prompt this will open an excel file:

<%
Response.ContentType = "application/vnd.ms-excel"

' contents here...
set objBinaryFile = Server.CreateObject("BinaryFileStream.Object")
Response.BinaryWrite objBinaryFile.GetFileBytes(CStr(strFilePathAndName))
set objBinaryFile = nothing
%>

BinaryFileStream object dll can be found here:
http://download.microsoft.com/download/excel2000/sample/2000/w9x2k/en-us/ChartGIF.exe

you'll need to set the proper mime type for each application document or the file will be prompted to
save. also the IUSR will need NTFS read permissions on these files
You can also open the file as an ado stream..

her's a link of common mime types.. you can set a function to assosiate each file extention to a mime
type response..

http://hostutopia.com/support/s058.html 

Commented:
aspnewbie,

Easy, faster way for word:

<%

Set wrd = CreateObject("Word.Application")
wrd.Documents.Open Server.MapPath("aa.doc")
wrd.Visible = False

wrd.Application.ActiveDocument.SaveAs Server.MapPath("aa.html"), 8
wrd.Application.quit
Set wrd = Nothing

%>


For the power point

<%
Set Wrd = CreateObject("PowerPoint.Application")
Wrd.Presentations.Open (Server.MapPath("power.ppt"))
wrd.Visible = False

wrd.Application.ActivePresentation.SaveAs Server.MapPath("aa.html"), 8

wrd.Application.quit
Set wrd = Nothing
%>

Regards,
Wee Siong

Commented:
aspnewbie,

IF in the Excel:

<%
Set Wrd = CreateObject("Excel.Application")
Wrd.Presentations.Open (Server.MapPath("excel.xls")).Activate
wrd.Visible = False

wrd.Application.ActiveWorkbook.SaveAs Server.MapPath("aa.html"), 8

wrd.Application.quit
Set wrd = Nothing
%>

Regards,
Wee Siong
CERTIFIED EXPERT
Top Expert 2005

Commented:
I agree with weesiong, but it is a really bad idea to do this. If
any errors occur, they will do server-side, and any resulting dialogue boxes will be invisible to the
user. These errors can drain the server's resources, and in some cases, crash the server. A number of
Microsoft KnowledgeBase articles warn against the practice.

You would be much better off if you could find a way to generate txt files using the Scripting.FileSystemObject
as you can more easily trap errors and release errant objects.

Fritz the Blank

Author

Commented:
Anything wrong with the code:
<%
Set Wrd = CreateObject("powerpoint.Application")
Wrd.Presentations.Open ("d:\test.ppt")
wrd.Visible = False

wrd.Application.ActivePresentation.SaveAs "d:\test.html", 8

wrd.Application.quit
Set wrd = Nothing
%>

this is the error:
Error Type:
Microsoft PowerPoint 2002 (0x80048240)
Presentations.Open : Invalid request. The PowerPoint Frame window does not exist.
/test.asp, line 3

Commented:
aspnewbie,

Sorry something error in Excel format:

The correct one
<%
Set Wrd = CreateObject("Excel.Application")
Wrd.Workbooks.Open (Server.MapPath("excel.xls")).Activate
wrd.Visible = False

wrd.Application.ActiveWorkbook.SaveAs Server.MapPath("aa.html"), 8

wrd.Application.quit
Set wrd = Nothing
%>

Regards,
Wee Siong

Commented:
aspnewbie,

this is the error:
Error Type:
Microsoft PowerPoint 2002 (0x80048240)
Presentations.Open : Invalid request. The PowerPoint Frame window does not exist.
/test.asp, line 3
>>When you run the script, please make sure you have close the powerpoint windows.

REgards,
Wee Siong

Author

Commented:
powerpoint: yes, i have close the powerpoint windows.

excel: it can save, but the contents is strange. Besides that, there are few dialog box come out to save the multiple worksheet.

Commented:
aspnewbie,

Excel canot 100% convert to html, because if it got chart, it canot 100% convert to images.

The powerpoint i haven't try in here, but i think it should be work...... no sure, i will try it later.

Regards,
Wee Siong

Author

Commented:
seems like naas1 face the same problem with me in powerpoint.
http://experts-exchange.com/jsp/qShow.jsp?qid=20165294

Author

Commented:
siong: excel can convert to webpage by manually open excel file and then save as webpage.

So i think it can be done in asp as well.

Problem that i find in excel is not about chart. inside the excel file, i just test a normal string in 1 column.

Commented:
aspnewbie,

Okes, i have see the problem, try this:

<%
On Error Resume Next

xlhtml = 44
Set Wrd = CreateObject("Excel.Application")
Wrd.Workbooks.Open (Server.MapPath("excel.xls")).Activate
wrd.Visible = False

wrd.Application.ActiveWorkbook.SaveAs Server.MapPath("xlhtml.html"), xlhtml

wrd.Application.quit
Set wrd = Nothing

IF Err.Number > 0 Then
     Err.Raise 6  ' Raise an overflow error.
     Response.Write "Error # " & CStr(Err.Number) & " " & Err.Description
     Err.Clear    ' Clear the error.
End IF
%>

The power point version i will try in later.

Regards,
Wee Siong

Author

Commented:
well done siong....
by the way, what is the mistake??

i'll be waiting for the powerpoint :)

thanks

Commented:
aspnewbie,

The mistake because in each Office Tools got different code to convert to HTML exp: Word --> HTML using 8, Excel --> HTML using 44, Power Point --> HTML using ??, it make me trouble, so i am 1 by 1 to testing it :)

Regards,
Wee Siong
Commented:
aspnewbie,

For the power point :

<%
On Error Resume Next

ppSaveAsHTML = 12
Set Wrd = CreateObject("PowerPoint.Application")
wrd.Visible = True
Wrd.Presentations.Open (Server.MapPath("power.ppt"))
wrd.ActivePresentation.SaveAs Server.MapPath("aa.html"), ppSaveAsHTML
wrd.quit
Set wrd = Nothing

IF Err.Number > 0 Then
     Err.Raise 6  ' Raise an overflow error.
     Response.Write "Error # " & CStr(Err.Number) & " " & Err.Description & VBCRLF & "<br>"
     Err.Clear    ' Clear the error.
End IF
%>

Regards,
Wee Siong

Author

Commented:
well done.....
thanks a lot.
if u don't mind, may i know where you learn about this code?

Commented:
aspnewbie,

I mean learn this code from Microsoft Search, Yahoo Search, MSDN Search, EE Search, so this 1200 points no easy in me, but in last i also learn a new things :)

Regards,
Wee Siong

Commented:
I'm new to ASP and am creating a document management system where I also need to convert powerpoint files to html.  I've looked at the code above and am not sure how to incorporate it with files that the client uploads.  Can someone help a newbie?