.net组件COM Interop注册的有关问题:Excel中无法调用自定义函数
.net组件COM Interop注册的问题:Excel中无法调用自定义函数
我用C#制作了一个Excel的自定义函数插件,用来从数据库中取数.程序在开发的机子上没有什么问题,但到客户的机器上就有问题了,不能加载.
自定义函数插件项目的生成属性上选择了 "为Com Interop注册 ",所以在开发的机器上能正常运行,但在客户机上我用如下命令进行注册,却不能运行:
Regasm ngxs.dll /tlb /codebase
类型库和类型都注册了,在Excel的工具菜单下选择 "加载宏 "-> 自动化,
能找到我的组件,选择后,提示 "找不到加载宏 "mscoree.dll ",从列表中删除吗? ",选否,不删除,但在Excel的公式列表中找不到函数,也没有数据库登陆对话框出现,说明组件没有正常加载.而在开发的机子上,这是可以正常取数运行的.
所以我认为生成下面的 "为Com Interop注册 "和使用Regasm命令进行注册是有差异的,
那我该怎么进行注册呢,请各位务必指定一二!谢谢各位了.
以下是Excel函数的制作方法:
在VS2005中新建C#类库项目,选择生成属性为 "为Com Interop注册 ",
然后所有要向Excel暴露的函数类写成如下形式:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace NG新中大
{
[ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class 提货单
{
private static string m_OrderNo;
private DataTable m_Hts;
#region 注册
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type));
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type), false);
}
private static string GetSubKeyName(Type type)
{
string s = @ "CLSID\{ " + type.GUID.ToString().ToUpper() + @ "}\Programmable ";
return s;
}
#endregion 注册
public 提货单()
{
if (Conn.conn == null && !Conn.b_notlink)
{
Conn temp = new Conn();
我用C#制作了一个Excel的自定义函数插件,用来从数据库中取数.程序在开发的机子上没有什么问题,但到客户的机器上就有问题了,不能加载.
自定义函数插件项目的生成属性上选择了 "为Com Interop注册 ",所以在开发的机器上能正常运行,但在客户机上我用如下命令进行注册,却不能运行:
Regasm ngxs.dll /tlb /codebase
类型库和类型都注册了,在Excel的工具菜单下选择 "加载宏 "-> 自动化,
能找到我的组件,选择后,提示 "找不到加载宏 "mscoree.dll ",从列表中删除吗? ",选否,不删除,但在Excel的公式列表中找不到函数,也没有数据库登陆对话框出现,说明组件没有正常加载.而在开发的机子上,这是可以正常取数运行的.
所以我认为生成下面的 "为Com Interop注册 "和使用Regasm命令进行注册是有差异的,
那我该怎么进行注册呢,请各位务必指定一二!谢谢各位了.
以下是Excel函数的制作方法:
在VS2005中新建C#类库项目,选择生成属性为 "为Com Interop注册 ",
然后所有要向Excel暴露的函数类写成如下形式:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace NG新中大
{
[ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class 提货单
{
private static string m_OrderNo;
private DataTable m_Hts;
#region 注册
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type));
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type), false);
}
private static string GetSubKeyName(Type type)
{
string s = @ "CLSID\{ " + type.GUID.ToString().ToUpper() + @ "}\Programmable ";
return s;
}
#endregion 注册
public 提货单()
{
if (Conn.conn == null && !Conn.b_notlink)
{
Conn temp = new Conn();