Solved

converting MsWord doc to html dynamicly

Posted on 2001-07-06
25
290 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
migrate from classic ASP to C# .NET 5 69
Table header not displaying on Firefox and Chrome 7 139
is this a cms? 8 36
wordpress display sub menu only when click 12 24
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

862 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

23 Experts available now in Live!

Get 1:1 Help Now