怎样将数据库中的数据保存到客户端的word文档中?
解决方案 »
- treeview空间动态生成问题。
- asp.net三层架构如何使用repeater呈现父子表数据
- web只能登陆一次程序
- 小问题
- 什么东东嘛!
- 怎么把msdn收藏夹Copy出来
- 如何通过OracleParameter向数据库中插入空值?
- 求一存储过程!
- 如何设置嵌套在repeater里的datagird的ItemDataBound事件
- DataList中嵌套CheckBoxList问题求助!!!
- DataGrid 添色的问题
- 在Orcale过程中,生成了动态的insert 语句:Sql_insert:='insert into '|| srctable || '('||fielda,filedb||')'|| ' values( '|| a,b ||')
try
{
object Nothing=System.Reflection.Missing.Value;//调用默认参数
//取得Word文件保存路径
object [email protected];
Word.Application WordApp=new Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
Word.Document WordDoc=WordApp.Documents.Add(ref missing,ref missing,ref missing,ref missing);
//增加一表格
Word.Table table=WordDoc.Tables.Add(WordApp.Selection.Range,1,1,ref Nothing,ref Nothing);
//在表格第一单元格中添加自定义的文字内容
table.Cell(1,1).Range.Text=tbBody.Text;
WordDoc.Paragraphs.Last.Range.Text="欢迎参加学习!";
//将WordDoc文档对象的内容保存为DOC文档
WordDoc.SaveAs(ref filename,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
lbResult.Text="文档路径:<a href='"+tbPath.Text+"'>"+tbPath.Text+"</a>(点击链接查看)<br>生成结果:成功!";
2.用C#在服务器端引用word生成WordApplication,往里面写数据。此时服务器要装word
3.用C#在服务器端生成html文件,然后,动态输出该文件,注意把该文件输出的Content-Type改为word,这样,传到客户端后自动调用word打开,而word能打开html格式,满足需求
4.如果数据已经显示在客户端,可以用javascript生成WordApplication,然后将数据复制到剪切板,并粘贴到WORD里。