请问各位高手们,如何把网页里的数据导出到客户端的WORD并打开

remymartin 2005-11-18 09:38:24
我在做一个WEB程序,其中有一个页面是需要打印的,但由于别的需要,我把IE的工具栏都禁了,这样用JAVASCRIPT的PRINT打出来的效果非常之恶心,我就想到了把页面上的所有内容转到WORD上来打印,就可以进行格式的调整了。哪们高手能告诉我,如何把页面内容转到WORD(还有一张图片)上并即时打开,或者给我一个网页打印的好办法。分不够再给。
...全文
145 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gngnandgngn 2005-12-06
  • 打赏
  • 举报
回复
web打印一般都会转到pdf再打印的,而不会转到word
xczgb 2005-12-06
  • 打赏
  • 举报
回复
上面的可以保存到服务器

HttpContext.Current.Response.Charset ="GB2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-word";
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=" + excelName + ".doc");
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");

grid.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
grid.RenderControl(hw);

HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
xczgb 2005-12-06
  • 打赏
  • 举报
回复

if(grd.Items.Count!=0)
{
StringWriter tw=new StringWriter();
HtmlTextWriter hw=new HtmlTextWriter(tw);
grd.RenderControl(hw);
int intV;
string strFileName;
Random rd=new Random();
intV=rd.Next();
strFileName=DateTime.Now.Second.ToString()+DateTime.Now.Millisecond.ToString()+intV.ToString()+".doc";
string filenew=Page.MapPath("../uploading/"+strFileName);
FileStream fl=new FileStream(filenew,FileMode.CreateNew);
StreamWriter fw=new StreamWriter(fl,System.Text.Encoding.GetEncoding("GB2312"));
fw.WriteLine(tw.ToString());
fw.Close();
fl.Close();
string strScript = "<script language=javascript> window.open('../uploading/" + strFileName + "', '', 'left=50,top=50,resizable=1,scrollbars=1,width=500,height=400,menubar=1'); </script>";
Page.RegisterStartupScript("", strScript);
}
else
{
string strScript = "<script language=javascript>alert('此报表没有可下载信息!');</script>";
Page.RegisterStartupScript("", strScript);
}
szdufeng 2005-12-06
  • 打赏
  • 举报
回复
我用水晶倒到pdf
hxlwww 2005-12-06
  • 打赏
  • 举报
回复
我也有这个问题,希望互相切磋
remymartin 2005-11-18
  • 打赏
  • 举报
回复
自己的沙发,自己坐了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧