我看过这篇文章,但似乎无法解决这个问题:Resolving an ambiguous reference
我正在尝试在WPF中创建一个按钮,当点击浏览excel文件然后打开它时。但是我一直收到错误
'Path'是'system.windows.shapes.path'之间的模糊引用 和'system.io.path'
以下是我的代码。我试过明确使用
System.IO.Path.GetFullPath(fileDialog.FileName)
以下是我的完整代码:
using Microsoft.Win32;
using System.Windows;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
namespace Fasetto
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new WindowViewModel(this);
}
private void WindowCloseButton_Click(object sender, RoutedEventArgs e)
{
SystemCommands.CloseWindow(this);
}
private void WindowMinimizeButton_Click(object sender, RoutedEventArgs e)
{
SystemCommands.MinimizeWindow(this);
}
private void WindowMaximizeButton_Click_1(object sender, RoutedEventArgs e)
{
SystemCommands.MaximizeWindow(this);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
FileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm";
fileDialog.ShowDialog();
string location = System.IO.Path.GetFullPath(fileDialog.FileName);
}
}
public class Read_From_Excel
{
public void getExcelFile(string filename)
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(filename);
}
}
这是触发错误的行,变量'filename'用红色下划线标出:
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(filename);