Solved

converting MsWord doc to html dynamicly

Posted on 2001-07-06
25
287 Views
Last Modified: 2012-06-21
I want to make possible to users to upload an MsWord document to my site and that the ASP application will convert the document to an HTML document in order that everyone will be able to read it. I have an uploading com for doing the uploading.
I am interested to get the code for doing the conversion.
The same for MsExcell files.
0
Comment
Question by:SaadDani
  • 12
  • 12
25 Comments
 
LVL 1

Expert Comment

by:deestuar
ID: 6259313
You could invoke the ole automation objetc model for word and do as saveas. Alternativley to this you could use a text conversion filter. keypak do one which can convert from many formats but could be overkill!!
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6261110
deestuar,

Welcome to EE, and i look like your comments is no an ANSWER, please DONT LOCK the QUESTION!

SaadDani please reject the COMMENTS, i will tell you how to do it with asp.

Regards,
Wee Siong
0
 

Author Comment

by:SaadDani
ID: 6268832
weesiong

I did what you tell me to do and I am still waiting for your answer!!!
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6269426
SaadDani,

Sorry forget in here, i will post you the code tomorrow, now i want goto sleep :)

Regards,
Wee Siong
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6271903
SaadDani,

See this link:
http://support.microsoft.com/support/kb/articles/Q291/3/25.ASP

Regards,
Wee Siong
0
 
LVL 7

Accepted Solution

by:
weesiong earned 100 total points
ID: 6271923
SaadDani,

Exp:
<%

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

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

%>

Regards,
Wee Siong
0
 

Author Comment

by:SaadDani
ID: 6272268
I got an error of nn compatibility of type on

wrd.Application.ActiveDocument.SaveAs
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6272384
SaadDani,

You are running in PWS, IIS or?
and make sure you have permission to Save the file, and also make sure you have Word install :)


Regards,
Wee Siong
0
 

Author Comment

by:SaadDani
ID: 6272647
I am running it on win2000 IIS, word2000 installed, where permission to save can be set?
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6272657
SaadDani,

Sorry, i am no sure, i am testing in my PWS no any problem :)

Are you using the example i posted? the microsoft link i posted need to download the .exe file and install, but i no try it.

Regards,
Wee Siong
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6272663
SaadDani,

And post me your code :)

Regards,
Wee Siong
0
 

Author Comment

by:SaadDani
ID: 6272720
<%@ Language=VBScript %>

<% response.buffer = true
   Response.CacheControl="no-cache"
   Response.AddHeader "Pragma","no-cache"
   Response.Expires=0
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-8">

</script>
</head>

<body bgcolor="azure">
<center>

<%
   Dim mySmartUpload
   Dim fileAlreadyExist
   Dim connectionProblems

   'On Error Resume Next

   fileAlreadyExist = false
   connectionProblems = false

   Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

   mySmartUpload.Upload

   For each file In mySmartUpload.Files
           Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
           'if fsoObject.FileExists("..\" & application("docsDirectory") & docName & ".htm") then
        if fsoObject.FileExists("c:\haverim\documents\" & file.FileName) then
             fileAlreadyExist = true
           else
                     if LCase(right(file.FileName, 4)) = ".doc" then
                    file.SaveAs("c:\haverim\documents\" & file.FileName)

                    newFileName = left(file.FileName, len(file.FileName) - 3) & "html"
                    Const wdFormatHTML = "8"
                    Set wrd = CreateObject("Word.Application")
                    wrd.Documents.Open Server.MapPath("../documents/" & file.FileName)
                    wrd.Visible = False

                    wrd.Application.ActiveDocument.SaveAs Server.MapPath("../documents/" & newFileName), wdFormatHTML
                    wrd.Application.quit
                    Set wrd = Nothing


                       docName = newFileName
                  else
                    docName = file.FileName
               end if

             Set MyConnection = Server.CreateObject("ADODB.Connection")
             MyConnection.Open "DSN=elecDB;UID=;PWD=pkuyu9"

             MySQL = "INSERT INTO tblDocuments (do_owner, do_name, do_sug) "
             MySQL = MySQL & " VALUES (" & session("account") & ", '" & docName & "', "
             MySQL = MySQL & session("sug") & ")"

             'response.write(MySQL)
             MyRS = MyConnection.Execute(MySQL, numofRec, adCmdText)

             If MyConnection.Errors.Count > 0 Then
                       connectionProblems = true
                end if
        end if
   next

   if fileAlreadyExist then
          response.write("?ca ?a?? e/?ca ?a ?a?? ?u?a ua i??? e/?ci ,?aaia iee? ?ae a? iua ?a??")
          response.write("<p><a href='docs.asp'>a??c<a>")

   elseif connectionProblems then
      MyConnection.close

          Response.Write("Problems with the database, come back later...")
          response.write("<p><a href='docs.asp'>a??c<a>")
   else
      MyConnection.close
          response.redirect("docs.asp")
  end if

%>
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Expert Comment

by:weesiong
ID: 6272741
SaadDani,

The script no more problem, but:

Const wdFormatHTML = "8"

move outsite "FOR"

and tell me the fully error you got :)

Regards,
Wee Siong
0
 

Author Comment

by:SaadDani
ID: 6272782
??uaeau ?ii ?eoa ui Microsoft VBScript (0x800A000D)
??ae-auaia ui ??a: 'wrd.Application.ActiveDocument.SaveAs'
/docs/doAddDoc.asp, line 49

this is in hebrew
the first error mean: run time error
the second one: non compatibility type
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6272813
SaadDani,

non compatibility type  ==> Method Error or?

Why you dont want try do it in a short script to testing it can work first or not?

just using the example i posted and using this to testing it can work or not, this will easy debug :)

Regards,
Wee SIong
0
 

Author Comment

by:SaadDani
ID: 6272879
I did it, (a short script, and got same result
regards
SaadDani
0
 

Author Comment

by:SaadDani
ID: 6272911
I canceled the line with the const and it works, but there is another problem now, the html file is unreadable...
May be it is because I try to convert a word97 file (but this is exacxtly what I want to do...)
regards
0
 

Author Comment

by:SaadDani
ID: 6272922
I tried also with a word2000 file where was written "Hello Word" and few more word and this is the junk I got in the html file

?Ia!?a>?y !#?yyy yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyiYA7 ??0>bjbjUU . 7|7|yyyyyyl???????UNNNN Z U??rrrrrrrrdffffff$? >P??rrrrr?I??rr?IIIr"?r?rdIrdI?Id??drf 3sv AUrN?dd?0?d ?( dI?I????UHello world Abcde eU?Y ??eUO (>uZ?o(&(>yyyyo$??A$>y,1?h??. ??A!?"?#? $? %??A?A ?A i8@?y8 NormalCJ_H aJmH sH tH >> !! !yySaadC:\Haverim\documents\hello.docSaadC:\Haverim\documents\hello.htmly@??M@yyUnknownyyyyyyyyyyyyG??z ?yTimes New Roman5??Symbol3&? ?z ?yArial"q???h?[Wf?[Wf!? '??r0e?yy Hello worldSaadSaad?ya??ouOh<?+'?U0\????AIa ?u  $ 0<DLTc Hello worldellSaad woaad Normal.dotSaadl.d2adMicrosoft Word 9.0@@Z^W A@Z^W A?y?I??.??+,u?0o hp????  ??? A ?cSaado   Hello world ui?yyy ?yyy?yyy?yyyyyyy"?yyy?yyy?yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyRoot Entryyyyyyyyy AFp??v A$?1TableyyyyyyyyyyyyWordDocumentyyyyyyyySummaryInformation(yyyyDocumentSummaryInformation8yyyyyyyyyyyyCompObjyyyyjObjectPoolyyyyyyyyyyyyp??v Ap??v Ayyyyyyyyyyyy?yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy?y yyyy AFMicrosoft Word Document MSWordDoc
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6272985
SaadDani,

try this:

<%

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

%>

Using "8", but i believe will get same problem :(

Regards,
Wee Siong
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6272992
SaadDani,

>I canceled the line with the const and it works, but there is another problem now, the html file is
unreadable...
You must Save the file as :
wrd.Application.ActiveDocument.SaveAs Server.MapPath("aa.html"), 8

8 means convert it to HTML format, Word97 convert, i no try before :(

Regards,
Wee Siong

0
 

Author Comment

by:SaadDani
ID: 6273968
Great, it works...
maybe can you provide the code for excell files also...
Thanks
Dani
0
 

Author Comment

by:SaadDani
ID: 6273997
maybe
Const wdFormatHTML = 8
was needed instead of
Const wdFormatHTML = "8"

Dani
0
 

Author Comment

by:SaadDani
ID: 6274064
maybe
Const wdFormatHTML = 8
was needed instead of
Const wdFormatHTML = "8"

Dani
0
 

Author Comment

by:SaadDani
ID: 6274182
Thank you very much
Const wdFormatHTML = 8
 I found by myself for excel
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6275495
SaadDani,

Maybe you are right, but the first way also can working in me here :)

Excel --> HTML format, will you post other points?

Regards,
Wee Siong
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now