Link to home
Start Free TrialLog in
Avatar of SaadDani
SaadDaniFlag for Israel

asked on

converting MsWord doc to html dynamicly

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.
Avatar of deestuar
deestuar

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!!
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
Avatar of SaadDani

ASKER

weesiong

I did what you tell me to do and I am still waiting for your answer!!!
SaadDani,

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

Regards,
Wee Siong
ASKER CERTIFIED SOLUTION
Avatar of weesiong
weesiong

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I got an error of nn compatibility of type on

wrd.Application.ActiveDocument.SaveAs
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
I am running it on win2000 IIS, word2000 installed, where permission to save can be set?
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
SaadDani,

And post me your code :)

Regards,
Wee Siong
<%@ 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

%>
SaadDani,

The script no more problem, but:

Const wdFormatHTML = "8"

move outsite "FOR"

and tell me the fully error you got :)

Regards,
Wee Siong
??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
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
I did it, (a short script, and got same result
regards
SaadDani
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
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 worldellS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yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy?y yyyy AFMicrosoft Word Document MSWordDoc
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
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

Great, it works...
maybe can you provide the code for excell files also...
Thanks
Dani
maybe
Const wdFormatHTML = 8
was needed instead of
Const wdFormatHTML = "8"

Dani
maybe
Const wdFormatHTML = 8
was needed instead of
Const wdFormatHTML = "8"

Dani
Thank you very much
Const wdFormatHTML = 8
 I found by myself for excel
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