将数据从gridview转换为docx

时间:2017-11-27 10:15:46

标签: c# asp.net gridview ms-word docx

我正在尝试将Gridview数据导出到docx,但它不起作用。

        public static void SendToUserWord(GridView grid, string fileName, string type)
    {
        var response = HttpContext.Current.Response;

        response.Clear();
        response.AddHeader("content-disposition", string.Format("attachment; filename=\"{0}\"", fileName));
        response.Charset = "";
        response.ContentType = type == "doc" ? "application/vnd.ms-word" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
        response.ContentEncoding = Encoding.Default;
        response.Write("<head><meta http-equiv=\"content-type\" content=\"text/html; charset="
            + Encoding.Default.WebName + "\"></head>");
        response.Write(@"<style> td { mso-number-format:\@; } </style>");

        using (var writer = new HtmlTextWriter(response.Output))
        {
            grid.RenderControl(writer);
        }
        response.End();
    }

如何导出到doxc?

0 个答案:

没有答案