我的defalut.aspx里有个labe1控件,和datagrid控件,我在网上查了很多都只是把datagrid里的数据导出到word,有没有什么方法可以把datagrid以外的控件,即页面显示的所有信息都导入到word,请高手指教,我下面的程序如何修改
private void ExportDataGrid(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
datagrid1.RenderControl (hw );
Response.Write(tw.ToString());
Response.End();
}
protected void BtEord_Click(object sender, EventArgs e)
{
ExportDataGrid("application/ms-word", "Word.doc"); }
private void ExportDataGrid(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
datagrid1.RenderControl (hw );
Response.Write(tw.ToString());
Response.End();
}
protected void BtEord_Click(object sender, EventArgs e)
{
ExportDataGrid("application/ms-word", "Word.doc"); }
解决方案 »
- socket 缓冲区接收一定量数据以后 如何复位
- 帮忙看看代码哪里有问题,郁闷了!
- 不用bat,如何把ping结果写入文件?
- 请教大虾:如何使用OpenFileDialog,通过选择快捷方式,打开网上的文件?
- C#里面如何调用返回结果集的Oralce存储过程?
- c#高级编程 里面的例子怎么不对啊?
- greennetboy(绿色家园)请进,接分了!
- c# 文件夹监控 多线程发送流向 出错 帮忙看看
- 请各位姐姐哥哥进来看看,给我主持公道
- 《Programming C#, 2nd Ed.》
- 我用超链接至一个word文档,总是下载效果,怎样才能直接显示出这个word文档呢?
- 个人认为是很难的问题,关于通用事务处理类的解决办法的实现,急求
{
string filePath = Server.MapPath("DocFiles/" + FileName);
System.IO.FileStream myFileStream = new System.IO.FileStream
(filePath, System.IO.FileMode.Create);
System.IO.TextWriter write = new System.IO.StreamWriter(myFileStream, System.Text.Encoding.GetEncoding("gb2312"));
write.WriteLine("<html>");
write.WriteLine("<head>");
write.WriteLine("</head>");
write.WriteLine("<body>");
write.WriteLine(lblContent.Text);
write.WriteLine("</body>");
write.WriteLine("</html>");
write.Close();
}
您那有没有用word.dll的例子啊
Word.Application WordApp = new Word.ApplicationClass();
Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
这个word是怎么来的,需要添加什么引用吗?我加了Microsoft.Office.Interop.Word.dll,也没有用阿