这是我第一次尝试从一个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) 我是Python(2.7版)的新手.我一直在使用一些使用DDE功能捕获"实时市场数据"的excel工作簿 - 由一个市场数据提供商("Matriks",如果有关系)提供服务.
为了简化我的整个流程,我决定绕过这个excel工作簿来进行数据捕获,相反,我决定使用python代码来执行相同的任务.
问题是,1)当我使用Pythonwin运行代码(下面提供)时,我得到"错误:无法创建服务器".
2)我得到"ImportError:这必须是一个MFC应用程序 - 首先尝试'导入win32ui'"当我使用IDLE运行这个非常简单的代码时.
(当然,我下载并运行win32ui.)
任何帮助表示赞赏.
# DDE code
# excel equivalent of this code is: =MTX|DATA!EURUSD.SON
import win32ui
import dde
s=dde.CreateServer()
s.Create("MTX")
c=dde.CreateConversation(s)
c.ConnectTo("DATA","SON")
c.Connected()
c.Request("EURUSD")
# returns
# Traceback (most recent call last):
# File "C:\IQTrader\_script\_obj\DDEClient.py", line 12, in <module>
# import dde
# ImportError: This must be an MFC application - try 'import win32ui' first
Run Code Online (Sandbox Code Playgroud)