C#中如何实现点击Button后读取Word稳定并显示到WPF上!

风的期待 2014-10-23 10:03:56
WPF显示Word文档用什么控件??具体怎么实现的!!!
我是菜鸟哈所以问了这菜鸟问题,但是我觉得搞懂这个对我以后有很大帮助!!!!!
请大家多多指教,思路和代码都能够写出!!!!
...全文
418 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
1987andy 2014-10-27
  • 打赏
  • 举报
回复
1. 直接使用wpf的浏览器控件 2.使用DSOFramer(虽然有点老,但是今天看来还是挺适用的,只是最新版本的无法支持而已,我做过支持的2010) 3.自己用stream来读取。按格式写 ,或者使用flowdocument这样的文档对象
风的期待 2014-10-27
  • 打赏
  • 举报
回复
这是什么情况啊~~我倒出来了但是还是有问题!!!
风的期待 2014-10-27
  • 打赏
  • 举报
回复
风的期待 2014-10-27
  • 打赏
  • 举报
回复
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Word = Microsoft.Office.Interop.Word; using System.IO; namespace wordOpen1 { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { //Word.Application opd = new Microsoft.Office.Interop.Word.Application(); //Microsoft.Office.Interop.Word.Document doc = opd.Documents.Open(FileName: Path.Combine(_AppDomain.CurrentDomain.BaseDirectory,)); try { Word.Application app = new Microsoft.Office.Interop.Word.Application(); Word.Document doc = null; object unknow = Type.Missing; //app.Visible = true; string str = @"D:\test.doc"; object file = str; doc = app.Documents.Open(ref file, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow); //string temp = doc.Paragraphs[2].Range.Text.Trim(); string temp = doc.Content.Text.Trim(); testBox1.Text = temp; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } 用这代码调试之后虽然可以显示出word文档的内容但是还是会有问题!!
风的期待 2014-10-27
  • 打赏
  • 举报
回复
爱,还是要自己多看代码啊!!
  • 打赏
  • 举报
回复
没有。
风的期待 2014-10-26
  • 打赏
  • 举报
回复
没有人啊???自己顶下啊!!!!! string strA = new StreamReader(@"d:\test.doc", Encoding.UTF8).ReadToEnd();//a.txt内容 这行代码为什么能够获取txt的内容但是对于DOC的内容显示的就是乱码啊?

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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