• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

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.
0
SaadDani
Asked:
SaadDani
  • 12
  • 12
1 Solution
 
deestuarCommented:
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
 
weesiongCommented:
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
 
SaadDaniAuthor Commented:
weesiong

I did what you tell me to do and I am still waiting for your answer!!!
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
weesiongCommented:
SaadDani,

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

Regards,
Wee Siong
0
 
weesiongCommented:
SaadDani,

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

Regards,
Wee Siong
0
 
weesiongCommented:
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
 
SaadDaniAuthor Commented:
I got an error of nn compatibility of type on

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

And post me your code :)

Regards,
Wee Siong
0
 
SaadDaniAuthor Commented:
<%@ 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
 
weesiongCommented:
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
 
SaadDaniAuthor Commented:
??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
 
weesiongCommented:
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
 
SaadDaniAuthor Commented:
I did it, (a short script, and got same result
regards
SaadDani
0
 
SaadDaniAuthor Commented:
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
 
SaadDaniAuthor Commented:
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
 
weesiongCommented:
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
 
weesiongCommented:
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
 
SaadDaniAuthor Commented:
Great, it works...
maybe can you provide the code for excell files also...
Thanks
Dani
0
 
SaadDaniAuthor Commented:
maybe
Const wdFormatHTML = 8
was needed instead of
Const wdFormatHTML = "8"

Dani
0
 
SaadDaniAuthor Commented:
maybe
Const wdFormatHTML = 8
was needed instead of
Const wdFormatHTML = "8"

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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 12
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now