这是我第一次尝试从一个C#控制台应用程序中的excel中捕获一些数据.
我收到错误"无法将类型为'microsoft.Office.Interop.Excel.ApplicationClass'的COM对象转换为'microsoft.Office.Interop.Excel.Application'".
此代码使用"Microsoft Excel 12.0对象库",我提供了对Microsoft.Office.Interop.Excel的引用.
不过,我无法克服这个错误 - 我相信它有自己的快速解决方案.
我挖了一点这个网站并遇到了这个解决方案: Interop类型无法嵌入
但是,我无法理解所以无法实现建议的解决方案.
我的.Net版本是4.5.
很感谢任何形式的帮助.
提前致谢.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
namespace deneme
{
class Program
{
static void Main(string[] args)
{
Excel.Application xlApp = new Excel.Application();
xlApp.Visible = true; // <-- excel application
xlApp.DisplayAlerts = false;
// Open the workbook.
Excel.Workbook wBook = xlApp.Workbooks.Open("C:\\FNN\\XLA\\fnnComTemplate.xlsx",
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing); …Run Code Online (Sandbox Code Playgroud)