HTML2Word
Save HTML as Word or other file
<!--- code courtesy of Peters Stolz pstolz@usa.net --->
<!--- Try to connect to the Word application object --->
<CFTRY>
    <!--- If it exists, connect to it --->
    <CFOBJECT
        ACTION="CONNECT"
        CLASS="Word.Application"
        NAME="objWord"
        TYPE="COM">
  <CFCATCH>
  <!--- The object doesn''t exist, so create it --->
        <CFTRY>
            <CFOBJECT
                ACTION="CREATE"
                CLASS="Word.Application"
                NAME="objWord"
                TYPE="COM">
          <!--- Word isn''t installed, or ColdFusion doesn''t have access to it --->
          <CFCATCH TYPE="Object">
              <FONT COLOR="RED">Cannot create Word Object<BR>
              Make sure Word is installed and that ColdFusion has permissions to
              use the Word COM objects.</FONT>
              <CFABORT>
          </CFCATCH>
        </CFTRY>
  </CFCATCH>
</CFTRY> The following code will open an HTML file and convert it to a Word document. You can use the "SaveAs()"
method of the "Documents" collection to convert the HTML file to various other formats as well -- HTML
is only one of the options. <CFSCRIPT>
    // HTML file path
    HTMLFilePath = "d:\inetpub\wwwroot\myFile.html";
   
    // Destination path for new Word document
    // We leave off the extension since we''ll declare the file type later on
    WordFilePath = "d:\inetpub\wwwroot\myFile";
   
    // Open Word in the background
    objWord.Visible = false; 
   
    // Disable alerts such as: ''Save this document?''
    objWord.DisplayAlerts = false;              
   
    // Get the ''Documents'' collection
    objDoc = objWord.Documents; 
   
    // Open the HTML document
    newDoc = objDoc.open(HTMLFilePath);             
   
    /* Save it as a new Word document -- the extension will automatically
       be appended based on the file type we choose.
       Some of the file types to convert to:
       1 = .dot
       2 = .txt
       6 = .rtf
       9 = .asc
      10 = .ans
      11 = .doc
    */
    newDoc.SaveAs(WordFilePath,Val(11));   
     
    // The next line would convert it to RTF instead
    // newDoc.SaveAs(WordFilePath,Val(6)); 
     
    // Close the document
    newDoc.Close();
   
    // Quit Word
    objWord.Quit();
</CFSCRIPT>
 

cover
Buy Fusebox 5 & FLiP: Master-Class ColdFusion Applications
cover
Buy Fusebox 4 & FLiP: Master-Class ColdFusion Applications
cover
Buy ColdFusion Lists, Arrays, & Structures
cover
Buy ColdFusion XML Objects

Dedicated and Shared CF Hosting 2021