我正在尝试将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?