C# 在WPF中查看Word文档
我正在尝试使用以下代码在WPF I中编程查看word文档 我在这一行出现了这个错误C# 在WPF中查看Word文档,c#,.net,wpf,C#,.net,Wpf,我正在尝试使用以下代码在WPF I中编程查看word文档 我在这一行出现了这个错误public partial class main Window:Window 消息显示“Window”是“System.Windows.Window”和“Microsoft.Office.Interop.Word.Window”之间的不明确引用。怎么纠正呢 private void BrowseButton_Click(object sender, RoutedEventArgs e) { // Crea
public partial class main Window:Window
消息显示“Window”是“System.Windows.Window”和“Microsoft.Office.Interop.Word.Window”之间的不明确引用。怎么纠正呢
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
// Create OpenFileDialog
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".doc";
dlg.Filter = "Word documents (.doc)|*.doc";
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result == true)
{
if (dlg.FileName.Length > 0)
{
SelectedFileTextBox.Text = dlg.FileName;
string newXPSDocumentName =
String.Concat(System.IO.Path.GetDirectoryName(dlg.FileName), "\\",
System.IO.Path.GetFileNameWithoutExtension(dlg.FileName), ".xps");
// Set DocumentViewer.Document to XPS document
documentViewer1.Document =
ConvertWordDocToXPSDoc(dlg.FileName,
newXPSDocumentName).GetFixedDocumentSequence();
}
}
}
private void BrowseButton_单击(对象发送方,路由目标)
{
//创建OpenFileDialog
Microsoft.Win32.OpenFileDialog dlg=新的Microsoft.Win32.OpenFileDialog();
//为文件扩展名和默认文件扩展名设置筛选器
dlg.DefaultExt=“.doc”;
dlg.Filter=“Word文档(.doc)|*.doc”;
//通过调用ShowDialog方法显示OpenFileDialog
可为空的结果=dlg.ShowDialog();
//获取所选文件名并显示在文本框中
如果(结果==真)
{
如果(dlg.FileName.Length>0)
{
SelectedFileTextBox.Text=dlg.FileName;
字符串newXPSDocumentName=
String.Concat(System.IO.Path.GetDirectoryName(dlg.FileName),“\\”,
System.IO.Path.GetFileNameWithoutExtension(dlg.FileName),“.xps”);
//将DocumentViewer.Document设置为XPS文档
文档查看器1.文档=
ConvertWordDocToXPSDoc(dlg.FileName,
newXPSDocumentName).GetFixedDocumentSequence();
}
}
}
别名Word的窗口
类
using WordWindow = Microsoft.Office.Interop.Word.Window;
using Window = System.Windows.Window;
然后将使用Window
的位置从Word更改为使用新别名WordWindow
它的发展方向示例如下:
...
using System.IO;
using Microsoft.Office.Interop.Word;
using Microsoft.Win32;
using WordWindow = Microsoft.Office.Interop.Word.Window;
using Window = System.Windows.Window;
为什么个人拒绝使用谷歌作为工具或参考看看这里@DJKRAZE这个标题很糟糕。这与手头的问题没有任何关系。您必须完全限定您正在使用的名称空间
应用程序是一个在windows和Microsoft中都可以注意到的关键字。Interop以及OleAutomation意味着Microsoft应用程序。或者Window
我不明白我应该把这个放在哪里的意思,please@rose,使用
语句将其放在的其余部分下@罗斯:我已经更新了我的答案。我忘记了需要指定默认情况下要使用的窗口。