C# 找不到类型或命名空间名称Excel
所以我是一个新的C夏普用户。但是,在第4、18、19和20行,我收到以下错误: 找不到类型或命名空间名称Excel 我已将引用导入excel COM库,但没有任何效果C# 找不到类型或命名空间名称Excel,c#,C#,所以我是一个新的C夏普用户。但是,在第4、18、19和20行,我收到以下错误: 找不到类型或命名空间名称Excel 我已将引用导入excel COM库,但没有任何效果 using System; using System.IO; using System.Diagnostics; using Excel; namespace CallPython { class Program { private static bool ExcelCommentsChecker() {
using System;
using System.IO;
using System.Diagnostics;
using Excel;
namespace CallPython
{
class Program
{
private static bool ExcelCommentsChecker()
{
Excel.Application excelApp = new Excel.Application();
Excel.Workbook workBook = excelApp.Workbooks.Open(@"C:\Tools\comments.xlsx");
foreach (var worksheet in workBook.Worksheets()
if (worksheet.Comments != null)
{
Console.WriteLine("comments");
}
else
{
Console.WriteLine("The variable is set to false.");
}
//foreach (var row in worksheet.Rows)
// foreach (var cell in row.Cells)
// https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-add-and-delete-worksheet-comments
// https://www.c-sharpcorner.com/blogs/how-to-add-move-hide-remove-comments-to-an-excel-worksheet-cell-using-epplus-net-application-c-sharp-part-eight
//https://www.codeproject.com/Tips/801032/Csharp-How-To-Read-xlsx-Excel-File-With-Lines-of
// if (cell != null) // Do something with the cells
return false;
}
static void Main(string[] args)
{
// full path of python interpreter
string python = @"C:\Tools\python3\python.exe";
// python app to call
string myPythonApp = @"C:\Tools\wordchecksinglefile.py";
//https://www.codeproject.com/Tips/801032/Csharp-How-To-Read-xlsx-Excel-File-With-Lines-of
// Create new process start info
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
// make sure we can read the output from stdout
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
// start python app with 3 arguments
// 1st arguments is pointer to itself,
// 2nd and 3rd are actual arguments we want to send
myProcessStartInfo.Arguments = myPythonApp;
Process myProcess = new Process();
// assign start information to the process
myProcess.StartInfo = myProcessStartInfo;
// start the process
myProcess.Start();
// Read the standard output of the app we called.
// in order to avoid deadlock we will read output first
// and then wait for process terminate:
StreamReader myStreamReader = myProcess.StandardOutput;
string myString = myStreamReader.ReadLine();
/*if you need to read multiple lines, you might use:
string myString = myStreamReader.ReadToEnd() */
// wait exit signal from the app we called and then close it.
myProcess.WaitForExit();
myProcess.Close();
///
Console.WriteLine("Value received from script: " + myString);
System.Threading.Thread.Sleep(3000);
// write the output we got from python app
}
}
}
我知道这是一个导入错误,但我在C sharp方面还不够高级,无法知道发生此错误的位置。您使用的是
Office Interop对象
,但使用的命名空间不正确
我认为您希望在代码中使用单词Excel
,因此必须别名名称空间:
using Excel = Microsoft.Office.Interop.Excel;
那么它应该会起作用
Excel.Application excelApp = new Excel.Application();
并确保已将程序集
Microsoft.Office.Interop.Excel
添加到项目中 您正在使用Office互操作对象
,但使用的命名空间不正确
我认为您希望在代码中使用单词Excel
,因此必须别名名称空间:
using Excel = Microsoft.Office.Interop.Excel;
那么它应该会起作用
Excel.Application excelApp = new Excel.Application();
并确保已将程序集Microsoft.Office.Interop.Excel
添加到项目中 名称空间不是“Excel”。。是否添加了互操作库?这将帮助您找到名称空间的名称。名称空间不是“Excel”。。是否添加了互操作库?这将帮助您找到名称空间的名称