创建docx文件时出现问题 [英] Problem with creating docx file

查看:137
本文介绍了创建docx文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据提供的文本创建docx文件.
这是代码段,

I need to create docx file from the provided text.
Here is the code snippet,

<asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" Height="100"

            Width="280"></asp:TextBox>
        <asp:LinkButton ID="lb_Download" runat="server" Text="Download file" OnClick="lb_Download_Click"></asp:LinkButton>





protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtDescription.Text = "lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
        }
    }
    protected void lb_Download_Click(object sender, EventArgs e)
    {
        string strContents = null;
        strContents = txtDescription.Text;

        string attachment = "attachment; filename=test.docx";
        Response.ClearContent();
        Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
        Response.AddHeader("content-disposition", attachment);
        Response.Write(strContents);
        Response.End();
    }




当我打开这个创建的test.docx文件时,它给了我错误.
内容类型中的任何解决方案?




When I open this created test.docx file, it gives me error.
Any solution in the Content Type?

推荐答案

通过此链接,这可能对您有帮助

此处 [
Go through this link, this may helps you

Here[^]

Thanks
--RA


使用下面的行
Use the below line
Response.ContentType = "application/vnd.ms-word.document";


这篇关于创建docx文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆