我正在尝试将照片添加到Excel Spread表但仍然收到以下错误?
错误1无法嵌入互操作类型"Microsoft.Office.Interop.Excel.ApplicationClass".请改用适用的界面.
ApplicationClass(); 在下面的代码行中以红色加下划线:
xlApp = new Excel.ApplicationClass();
有人可以告诉我如何解决这个问题?
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
private void btnWriteSpreedSheet_Click(object sender, EventArgs e)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass(); //This is where the problem is??????
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//add some text
xlWorkSheet.Cells[1, 1] = "http://csharp.net-informations.com";
xlWorkSheet.Cells[2, 1] = "Adding picture in Excel File";
xlWorkSheet.Shapes.AddPicture("C:\\csharp-xl-picture.JPG", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 50, 50, 300, 45);
xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, …Run Code Online (Sandbox Code Playgroud) 我在我们正在使用的第三方库中找到了类似以下的代码.
[CoClass(typeof(BlahClass))]
public interface Blah : IBlah
{
}
Run Code Online (Sandbox Code Playgroud)
这到底是做什么的?msdn文档没有充分阐明这个主题让我遵循.
我想从C#4.0(VS 2010 Express Edition)调用Excel Sheet.
当我宣布时,
Microsoft.Office.Interop.Excel.ApplicationClass excel =
new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.Visible = true;
Run Code Online (Sandbox Code Playgroud)
我收到错误了
无法嵌入Interop类型"Microsoft.Office.Interop.Excel.ApplicationClass".请改用适用的界面.
什么是灵魂?
我必须开发一个程序,它在本地PC上作为服务运行,为服务器提供几个用户状态.一开始我必须检测用户登录和注销.
我的想法是使用ManagementEventWatcher该类并查询Win32_LogonSession是否有更改的通知.
我的第一个测试运行良好,这是代码部分(这将作为服务的线程执行):
private readonly static WqlEventQuery qLgi = new WqlEventQuery("__InstanceCreationEvent", new TimeSpan(0, 0, 1), "TargetInstance ISA \"Win32_LogonSession\"");
public EventWatcherUser() {
}
public void DoWork() {
ManagementEventWatcher eLgiWatcher = new ManagementEventWatcher(EventWatcherUser.qLgi);
eLgiWatcher.EventArrived += new EventArrivedEventHandler(HandleEvent);
eLgiWatcher.Start();
}
private void HandleEvent(object sender, EventArrivedEventArgs e)
{
ManagementBaseObject f = (ManagementBaseObject)e.NewEvent["TargetInstance"];
using (StreamWriter fs = new StreamWriter("C:\\status.log", true))
{
fs.WriteLine(f.Properties["LogonId"].Value);
}
}
Run Code Online (Sandbox Code Playgroud)
但我有一些理解问题,我不确定这是否是解决该任务的常用方法.
如果我查询Win32_LogonSession我得到几个与同一用户相关联的记录.例如,我得到这个ID 7580798和7580829,如果我查询
ASSOCIATORS OF {Win32_LogonSession.LogonId = X} WHERE …
这是我第一次尝试从一个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) 嗨,我有一个列表容器,其中包含值列表.我希望将列表值直接导出到Excel.有没有办法直接做到这一点?
是否可以使用NuGet来分发COM DLL?
我该如何设置包装?
我想我可以将DLL放在Tools目录中,然后运行安装后脚本来注册库,但我不是很擅长PowerShell.
是否有任何在线示例如何执行此操作(如果可能)?
我在C#中添加了arcmap的应用程序,我尝试连接我的文件地理数据库.所以当我试图运行它时,我收到了这个错误:
Error 1 Interop type 'ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass' cannot be embedded. Use the applicable interface instead.
Run Code Online (Sandbox Code Playgroud)
然后是添加的路径
我之前从未见过这个错误,我想知道出了什么问题.
这是它的主要代码:
public IWorkspace FileGdbWorkspaceFromPropertySet(string database)
{
IPropertySet propertySet = new PropertySetClass();
propertySet.SetProperty("DATABASE", database);
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
return workspaceFactory.Open(propertySet, 0);
}
Run Code Online (Sandbox Code Playgroud)
所以错误在这一行:
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
Run Code Online (Sandbox Code Playgroud)
我希望有人可以向我提供这个错误的解释,也可以解决我的问题.
出了什么问题?
我正在尝试编写一个简单的程序,它将连接到远程计算机并查询索引状态.
这是在我的机器上执行的代码.这很好用.
using System;
using Microsoft.Search.Interop;
namespace IndexStatus
{
class Program
{
static void Main(string[] args)
{
CSearchManager manager = new CSearchManager();
CSearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");
_CatalogPausedReason pReason;
_CatalogStatus pStatus;
Console.WriteLine(catalogManager.NumberOfItems().ToString());
int plIncrementalCount;
int plNotificationQueue;
int plHighPriorityQueue;
catalogManager.NumberOfItemsToIndex(out plIncrementalCount, out plNotificationQueue, out plHighPriorityQueue);
Console.WriteLine(plIncrementalCount.ToString());
Console.WriteLine(plNotificationQueue.ToString());
Console.WriteLine(plHighPriorityQueue.ToString());
catalogManager.GetCatalogStatus(out pStatus, out pReason);
Console.WriteLine(pStatus.ToString() + " " + pReason.ToString());
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
然而,当我打电话GetCatalog的"mycomputername.SystemIndex",而不是"SystemIndex",我得到
IndexStatus.exe中发生未处理的"System.Runtime.InteropServices.COMException"类型异常
附加信息:HRESULT的异常:0x80042103
Visual Studio 2015在Windows 8.1上以管理员权限运行.目标计算机主要是Windows 7系统,程序主要从Windows 10系统运行.我正在使用从此处下载的Microsoft Windows Search 3.X …
我在X509Enrollment.CX509CertificateRequestPkcs10对象上的InitializeFromPrivateKey()中指定模板参数时遇到问题.除"用户"模板以外的任何内容都会导致以下异常: -
CertEnroll :: CX509CertificateRequestPkcs10 :: InitializeFromPrivateKey:此CA不支持所请求的证书模板.0x80094800(-2146875392)
我需要使用一个特定的证书模板,当我尝试它时,代码会抛出异常.该模板存在于CA上,并且位于运行以下代码的客户端计算机上.
Javascript代码如下:
<script type="text/javascript">
var sCertificate = null;
var sDistinguishedName = "C=\"\";S=\"\";L=\"\";O=\"XXXXX\";OU=\"XXXXXXX\";E=\"XXXXX@XXXX.com\";CN=\"xxxxxxx\";";
var template = "RegistrationCert"; //Anything Other than "User" fails, have tried template Oid too.
var classFactory = new ActiveXObject("X509Enrollment.CX509EnrollmentWebClassFactory");
var objEnroll = classFactory.CreateObject("X509Enrollment.CX509Enrollment");
var objPrivateKey = classFactory.CreateObject("X509Enrollment.CX509PrivateKey");
var objRequest = classFactory.CreateObject("X509Enrollment.CX509CertificateRequestPkcs10");
var objDN = classFactory.CreateObject("X509Enrollment.CX500DistinguishedName");
objPrivateKey.ProviderName = "Microsoft Enhanced Cryptographic Provider v1.0";
objPrivateKey.KeySpec = "1";
objPrivateKey.ProviderType = "1";
try
{
objRequest.InitializeFromPrivateKey(1, objPrivateKey, template);
objDN.Encode(sDistinguishedName, 0); …Run Code Online (Sandbox Code Playgroud) javascript templates certificate certificate-authority certenroll
我写了一个简单的基于FTP的文件同步程序.其设置可以存储在XML文件中.我希望用户能够使用各种配置快速打开程序.所以我设置程序,以便能够通过命令行参数读取配置文件的路径.这样,可以基于不同的配置文件在桌面上创建快捷方式.现在,我正在尝试添加一项功能,该功能将自动为特定配置文件创建快捷方式.
我尝试过使用ShellLink.cs 这篇文章中的例子.我已经使用IWshRuntimeLibrary描述也试图在这里.我可以创建快捷方式,但属性窗口中快捷方式的"目标类型"在新快捷方式中最终为空白.如果我双击快捷方式,我会从Windows获取一个错误窗口,关于它在提供的路径中找到FooBar.xml时遇到问题.所以它似乎没有意识到应该启动一个不打开文件的应用程序.
现在,如果我打开新快捷方式的属性并在目标字段中更改某些内容,然后将其更改回来.例如,从xml中删除x,然后将其添加回来.单击确定后,快捷方式的图标会立即切换到我的应用程序的图标,并在双击时正常工作.
因此,当我手动编辑快捷方式时,它会强制窗口检查快捷方式目标类型是否应该是应用程序并切换它.
那么当目标路径不以.exe结尾时,我怎样才能通过C#创建一个目标类型为Application的新快捷方式?
c# ×8
excel ×3
.net ×1
appdomain ×1
arcgis ×1
arcobjects ×1
c#-4.0 ×1
certenroll ×1
certificate ×1
coclass ×1
com ×1
com-interop ×1
esri ×1
events ×1
javascript ×1
logoff ×1
ms-office ×1
nuget ×1
process ×1
shortcuts ×1
templates ×1
windows ×1
winforms ×1