我想只需点击一下即可创建HTML页面的docx文件。
这是怎么回事,我有一个HTML页面,页面底部有一个“下载”按钮。单击该按钮时,该页面将导出到docx文件中。我如何通过使用经典的asp?
实现这一目标这是我做的,一旦我运行编码,页面就会导出到ms字。
<!DOCTYPE html>
<html>
<head>
<%response.write("<h1><center>Welcome!</h1>")%>
<center><img src="http://www.themelab.com/wp-content/uploads/smiley.jpg" alt="Smiley" style="width:auto;height:auto;"></center>
<style>
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;
}
</style>
</head>
<body>
<h1> </h1>
<table>
<tr>
<th>Name</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
<p>Click the button below to copy the page as word document.</p>
<button class="word-export"> Download </button>
<%
Response.Buffer = TRUE
Response.ContentType = "application/msword"
%>
</body>
</html>
我希望仅在单击按钮后才导出它。或者如何在单击按钮后运行以下代码?
<%
Response.Buffer = TRUE
Response.ContentType = "application/msword"
%>
请帮帮我。谢谢。
答案 0 :(得分:0)
您应该向页面发出请求,因为您需要表单并提交表单,请输出ms字样:
<%if Request("btn_download")<>"" Then
'Only set the headers if this is request for download
Response.Buffer = TRUE
Response.ContentType = "application/msword"
Response.AddHeader "content-disposition","attachment; filename=thefile.doc;"
end if
%>
<!DOCTYPE html>
<html>
<head>
<%response.write("<h1><center>Welcome!</h1>")%>
<center><img src="http://www.themelab.com/wp-content/uploads/smiley.jpg" alt="Smiley" style="width:auto;height:auto;"></center>
<style>
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;
}
</style>
</head>
<body>
<h1> </h1>
<table>
<tr>
<th>Name</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
<%if Request("btn_download")="" Then
'Show the download button only if the button has not been clicked.
%>
<p>Click the button below to copy the page as word document.</p>
<form>
<input type="submit" class="word-export" name="btn_download" value="Download">
</form>
<%End If%>
</body>
</html>