Hi @Urs Wagner
Here is the repo link:
https://github.com/sasinaola/WpfAppExcel.git
Success.
Sina
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello
I am using .NET 6 and I want to open the Excel file with Microsoft.Office.Interop.Excel.
Calling the constructor of my C# class I get this error:
System.IO.FileNotFoundException: 'Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.'
I have installed Microsoft.Interop.Excel Nuget package.
I have installed in Visual Studio the office tools.
I am using the same code with .NET Framework 4.8. It is working fine.
Must a use another library?
In summary, you will need to install the version of Microsoft Office Excel on that system, that has not been expired.
Your machine needs to have the corresponding version of Office installed. 15.0.0.0 should correspond to Office 2013 - that needs to be installed on your target machine (other versions of Office may not work). This almost certainly means you're using MSOffice interop libraries, which only work if office is installed and against the same version.
Alternatively, you could refactor your code to just directly read the Excel XML.
Let me know if the above is helpful. Then, we can move forward. I have a typical application that can call any Microsoft Office irrespective of their version.
Thank You for Your answer.
Does this version 15.0.0.0 not work for Office 2016?
We have Office 2016 installed. I can't find a newer Microsoft.Office.Interop.Excel library,$
Hi @Urs Wagner
Try to do this I strongly it will work, because it worked for me to invoke any version of Office. (Now for Excel in this context).
// More Code
}
Let me know how it goes.
Regards,
Sina
Hi @Urs Wagner
I have have been doing this more than decades and it work fine.
I created new app using .NET 7 preview VS 2022, while I also created WPF App with .NET 6 stable. Just because of you to affirm.
Actually, my old applications works fine and the new one work fine too. However, see the below codes and steps:
using Microsoft.Office.Interop;
using ExcelAdaptorLib = Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
using ExcelAdaptorLib;
namespace WpfAppExcel
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Excel.Application objExcel = new Excel.Application();
objExcel.Visible = true;
}
}
}
Now, before the above code add your reference in COM
Notice new version 16.0, also, check your package for alert, if there is any on security warning perhaps you add testing for excelTools, remove it for now.
Wishing you good success, I can create a video of it on weekend.
cheers and my regards,
Sina