Download HTML page as .docx with Classic ASP
<p>I'm creating an HTML page that can be downloaded as .docx after user click Download button. I've managed to download .docx file but when I try to open it, a popup came out saying "The file is corrupt and cannot be opened".</p>

<p>Fyi, I have tried using these:</p>

<pre><code>Response.ContentType = "application/vnd.ms-word"
Response.ContentType = "application/octet-stream"
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
</code></pre>

<p>How do I get every data (image and table) from HTML page into ms word with extension docx by using Classic ASP? </p>

<pre><code>&lt;%if Request("btn_download")&lt;&gt;"" Then 
'Only set the headers if this is request for download
    Response.Buffer = TRUE
    Response.ContentType = "application/vnd.ms-word"
    Response.AddHeader "content-disposition","attachment; filename=thefile.docx;"
end if
%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;

&lt;%response.write("&lt;h1&gt;&lt;center&gt;Welcome!&lt;/h1&gt;")%&gt;
&lt;center&gt;&lt;img src="http://www.themelab.com/wp-content/uploads/smiley.jpg" alt="Smiley" style="width:auto;height:auto;"&gt;&lt;/center&gt;

&lt;style&gt;
table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;h1&gt;&amp;nbsp;&lt;/h1&gt;
&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Name&lt;/th&gt;
    &lt;th&gt;Contact&lt;/th&gt;
    &lt;th&gt;Country&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Alfreds Futterkiste&lt;/td&gt;
    &lt;td&gt;Maria Anders&lt;/td&gt;
    &lt;td&gt;Germany&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Centro comercial Moctezuma&lt;/td&gt;
    &lt;td&gt;Francisco Chang&lt;/td&gt;
    &lt;td&gt;Mexico&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Ernst Handel&lt;/td&gt;
    &lt;td&gt;Roland Mendel&lt;/td&gt;
    &lt;td&gt;Austria&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Island Trading&lt;/td&gt;
    &lt;td&gt;Helen Bennett&lt;/td&gt;
    &lt;td&gt;UK&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Laughing Bacchus Winecellars&lt;/td&gt;
    &lt;td&gt;Yoshi Tannamuri&lt;/td&gt;
    &lt;td&gt;Canada&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Magazzini Alimentari Riuniti&lt;/td&gt;
    &lt;td&gt;Giovanni Rovelli&lt;/td&gt;
    &lt;td&gt;Italy&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;%if Request("btn_download")="" Then 
'Show the download button only if the button has not been clicked.
%&gt;
&lt;p&gt;Click the button below to copy the page as word document.&lt;/p&gt;
&lt;form&gt;
&lt;input type="submit" name="btn_download" value="Download"&gt;
&lt;/form&gt;
&lt;%End If%&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>