简体   繁体   English

从aspx页面下载Word可编辑文档

[英]Download a Word editable document from an aspx page

I currently have an aspx page returning a html form (with images and css). 我目前有一个返回HTML表单(带有图像和CSS)的aspx页面。 I would like get a download Word editable version of this form without rewrite all the code. 我想要下载此表格的Word可编辑版本,而无需重写所有代码。 Is it possible ? 可能吗 ?

An example : I Have a page 'WebForm2.aspx' with a simple content like this. 一个例子:我有一个页面'WebForm2.aspx',上面有一个简单的内容。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" 
Inherits="WebApplication15.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Title</h1>
        <asp:CheckBox runat="server" ID="myTest" Text="Doc 1" /><br />
        <asp:CheckBox runat="server" ID="myTest2" Text="Doc 2" /><br />
        <asp:CheckBox runat="server" ID="myTest3" Text="Doc 3" /><br />
        <asp:CheckBox runat="server" ID="myTest4" Text="Doc 4" /><br />
    </div>
    </form>
</body>
</html>

I would like that from an other page for example a button that lets you download the contents of 'WebForm2.aspx' in an editable Word document. 我希望从其他页面获得该信息,例如,一个按钮,可让您下载可编辑Word文档中的“ WebForm2.aspx”的内容。

I Add this in Page_PreRender method 我在Page_PreRender方法中添加它

Response.AddHeader("Content-Type", "application/msword");

It's partially work. 部分工作。 If I save the document css and images aren't loaded but if I only open the downloadable content css and images are loaded. 如果保存文档,则不会加载CSS和图像,但是如果仅打开可下载的内容,则会加载CSS和图像。

MS Word can edit html document so by adding Content-Type=application/msword record in header will make browser open your page in browser unfortunately without css and images. MS Word可以编辑html文档,因此不幸的是,通过在标头中添加Content-Type = application / msword记录,不幸的是,浏览器无法使用CSS和图像在浏览器中打开页面。

Add following code in prerender event on your page 在页面上的prerender事件中添加以下代码

    Response.AddHeader("Content-Type", "application/msword");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM