[英]Compiling C# code with CSC - excel interop
I am struggling with the following error when compiling my C# code with CSC - "error CS0234: The type or namespace name 'Core' does not exits in the namespace 'Microsoft.Office' (are you missing an assembly)" 使用CSC编译C#代码时,我在以下错误中苦苦挣扎-“错误CS0234:类型或名称空间名称'Core'不在名称空间'Microsoft.Office'中退出(您是否缺少程序集)“
I've had zero experience with object oriented programming before tackling this project. 在完成该项目之前,我在面向对象编程方面经验为零。 It involves automation of a couple devices through serial commands. 它涉及通过串行命令自动化几个设备。 Parameters are read from a native Excel file and data is written to Excel files that the code creates. 从本地Excel文件中读取参数,并将数据写入代码创建的Excel文件中。
Here's what think maybe pertinent: 以下是可能相关的想法:
Here is the header to my code 这是我的代码的标题
using System; 使用系统; using System.Collections.Generic; 使用System.Collections.Generic; using System.Linq; 使用System.Linq; using System.Text; 使用System.Text; using System.IO.Ports; 使用System.IO.Ports; using System.Threading; 使用System.Threading; using Microsoft.Office.Core; 使用Microsoft.Office.Core; using Excel = Microsoft.Office.Interop.Excel; 使用Excel = Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel; 使用Microsoft.Office.Interop.Excel;
namespace ConsoleApplication1 { class Program { static void Main(string[] args) 命名空间ConsoleApplication1 {类Program {静态void Main(string [] args)
Follow-up question (if I get this working) what things do I need to worry about to make this run on another computer? 后续问题(如果我能解决这个问题),我需要担心什么事情才能使其在另一台计算机上运行? My thoughts was that all I needed was the .excel.dll and the .exe file in the same directory structure? 我的想法是,我需要的只是.excel.dll和.exe文件在同一目录结构中吗? (At this time I don't know what version of .NET or Office is being run on the target computer - my guess would be at least it would be Office 2010.) (目前,我不知道目标计算机上正在运行哪个版本的.NET或Office-我的猜测至少是Office2010。)
Any guidance would be greatly appreciated. 任何指导将不胜感激。 I've been wearing out google on this one for the past week+ 在过去的一周里,我一直在用这个Google工具
Regards, Keith 问候,基思
I know this is not the exact answer you're looking for, but I'm posting it because I think it would be more helpful than directly answering your question. 我知道这不是您要找的确切答案,但我将其发布是因为我认为这比直接回答您的问题更有用。
You would save yourself a LOT of time by downloading Visual C# 2010 Express and letting the IDE do the heavy lifting for you. 通过下载Visual C#2010 Express并让IDE为您完成繁重的工作,您可以节省很多时间。
It sounds like you need to add a reference, which means referencing an existing .dll file somewhere. 听起来您需要添加引用,这意味着在某处引用现有的.dll文件。 I know if can be done via the command line, but it's a LOT easier to use the IDE. 我知道是否可以通过命令行来完成,但是使用IDE要容易得多。
It's free, and can be found here: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-csharp-express 它是免费的,可以在这里找到: http : //www.microsoft.com/visualstudio/zh-cn/products/2010-editions/visual-csharp-express
There's a How-To guide for Office Interop here: http://msdn.microsoft.com/en-us/library/dd264733.aspx 这里有Office Interop的操作指南: http : //msdn.microsoft.com/zh-cn/library/dd264733.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.