Excel:AddIn,填充活动表格单元格? [英] Excel: AddIn, fill active sheet cell ?
问题描述
你好,
我为excel 2003用udf制作了一个小的AddIn。
我使用的是vs2003。
观点是函数__T()
我在excel表格中称它为__ T()[输入]
我不是能够为给定的单元格设置一个值。
region.Value2 =" qwe" ;; // bumm!
将播放异常。在所有有excel的电脑上。
HRESULT 0x800A03EC
是否有注册问题?
但是,它可以读取工作表的名称。
s = ws.Name.ToString(); //好吧!
谁知道,问题是什么?
谢谢
microsoft.public.dotnet .languages.csharp
使用System;
使用System.Runtime.InteropServices;
使用Microsoft.Win32;
使用Excel = Microsoft.Office.Interop.Excel; // ist nicht auf jedem系统。
Nachinstallieren ???
命名空间ExcelAddInFunc
{
[ClassInterface( ClassInterfaceType.AutoDual)]
公共类fncAdd
{
public fncAdd()
{
}
public string __T()
{
string s =" Test" ;
Excel.Application m_objExcel =
(Excel.Application)Marshal.GetActiveObject(" Excel.Application");
Excel.Worksheet ws =
(Excel.Worksheet)m_objExcel.ActiveWorkbook.ActiveS heet;
Excel.Range region =(Excel.Range)ws.Cells [10,10];
s = ws.Name.ToString(); //好吧!
试试
{
region.Value2 =" qwe" ;; // bumm!
}
catch(例外e)
{
s = e.ToString();
}
返回s;
}
}
Hello,
I have made an small AddIn with udf for excel 2003.
I use vs2003.
The point of view is the function __T()
I call it in excel sheet writing =__T() [enter]
I am not able to set a value to a given cell.
region.Value2="qwe"; //bumm!
A exception will be trown. On all PCs with excel.
HRESULT 0x800A03EC
Is it com-registration problem?
But, it is possible to read the name of worksheet.
s=ws.Name.ToString(); //OK!
Who knows, what is the problem?
Thanks
microsoft.public.dotnet.languages.csharp
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Excel=Microsoft.Office.Interop.Excel; // ist nicht auf jedem System.
Nachinstallieren???
namespace ExcelAddInFunc
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class fncAdd
{
public fncAdd()
{
}
public string __T()
{
string s="Test";
Excel.Application m_objExcel =
(Excel.Application)Marshal.GetActiveObject("Excel. Application");
Excel.Worksheet ws =
(Excel.Worksheet)m_objExcel.ActiveWorkbook.ActiveS heet;
Excel.Range region=(Excel.Range)ws.Cells[10,10];
s=ws.Name.ToString(); //OK!
try
{
region.Value2="qwe"; //bumm!
}
catch(Exception e)
{
s=e.ToString();
}
return s;
}
}
推荐答案
弗兰克,
是否还有其他信息?最重要的是,你是否确定该地区已填充,而不是空?
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
" Frank M. Walter" <˚F****** @ hotmail.com>在消息中写道
news:44 *********************** @ news.freenet.de ...
Frank,
Is there any more information to the exception? On top of that, are you
sure that region is populated, and not null?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Frank M. Walter" <f.******@hotmail.com> wrote in message
news:44***********************@news.freenet.de...
您好,我已经为excel 2003用udf做了一个小的AddIn。
我用vs2003。
观点是函数__T()
我无法为给定的单元格设置值。
region.Value2 =" qwe" ;; // bumm!
将播出一个例外。在所有具有excel的PC上。
HRESULT 0x800A03EC
是否有注册问题?
但是,可以读取工作表的名称。
s = ws.Name.ToString(); //好的!
谁知道,问题是什么?
谢谢
microsoft.public.dotnet.languages.csharp
使用System;
使用System.Runtime.InteropServices;
使用Microsoft.Win32;
使用Excel = Microsoft.Office.Interop.Excel; // ist nicht auf jedem系统。
Nachinstallieren ???
命名空间ExcelAddInFunc
{ClassInterface(ClassInterfaceType.AutoDual)]
公共类fncAdd
公共fncAdd()
{
}
公共字符串__T()
{
字符串s =" Test";
Excel.Application m_objExcel =
(Excel.Application)Marshal.GetActiveObject(" Excel.Application");
Excel.Worksheet ws =
(Excel.Worksheet)m_objExcel.ActiveWorkbook.ActiveS heet;
Excel.Range region =(Excel.Range)ws.Cells [10,10];
s = ws.Name.ToString (); //好的!
尝试
{/> region.Value2 =" qwe" ;; // bumm!
}
catch(例外e)
{
s = e.ToString();
}
返回s;
}
}
Hello,
I have made an small AddIn with udf for excel 2003.
I use vs2003.
The point of view is the function __T()
I call it in excel sheet writing =__T() [enter]
I am not able to set a value to a given cell.
region.Value2="qwe"; //bumm!
A exception will be trown. On all PCs with excel.
HRESULT 0x800A03EC
Is it com-registration problem?
But, it is possible to read the name of worksheet.
s=ws.Name.ToString(); //OK!
Who knows, what is the problem?
Thanks
microsoft.public.dotnet.languages.csharp
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Excel=Microsoft.Office.Interop.Excel; // ist nicht auf jedem System.
Nachinstallieren???
namespace ExcelAddInFunc
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class fncAdd
{
public fncAdd()
{
}
public string __T()
{
string s="Test";
Excel.Application m_objExcel =
(Excel.Application)Marshal.GetActiveObject("Excel. Application");
Excel.Worksheet ws =
(Excel.Worksheet)m_objExcel.ActiveWorkbook.ActiveS heet;
Excel.Range region=(Excel.Range)ws.Cells[10,10];
s=ws.Name.ToString(); //OK!
try
{
region.Value2="qwe"; //bumm!
}
catch(Exception e)
{
s=e.ToString();
}
return s;
}
}
Hello Nicholas,
the正在调用函数。
没有关于异常的更多信息。
Frank
" Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag新闻:%2 **************** @ TK2MSFTNGP05.phx.gbl ...
Hello Nicholas,
the function is being called.
There is no more information about exception.
Frank
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:%2****************@TK2MSFTNGP05.phx.gbl...
Frank,
是否还有其他信息?最重要的是,你确定该区域是否已填充,而不是null?
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
Frank M. Walter <˚F****** @ hotmail.com>在消息中写道
新闻:44 *********************** @ news.freenet.de ...
Frank,
Is there any more information to the exception? On top of that, are
you sure that region is populated, and not null?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Frank M. Walter" <f.******@hotmail.com> wrote in message
news:44***********************@news.freenet.de...
您好,我已经为excel 2003用udf做了一个小的AddIn。
我使用vs2003。
观点是函数__T()
我打电话它在excel表写入= __ T()[enter]
我无法为给定的单元格设置值。
region.Value2 =" qwe" ;; // bumm!
将播出一个例外。在所有具有excel的PC上。
HRESULT 0x800A03EC
是否有注册问题?
但是,可以读取工作表的名称。
s = ws.Name.ToString(); //好的!
谁知道,问题是什么?
谢谢
microsoft.public.dotnet.languages.csharp
使用System;
使用System.Runtime.InteropServices;
使用Microsoft.Win32;
使用Excel = Microsoft.Office.Interop.Excel; // ist nicht auf jedem
系统。 Nachinstallieren ???
命名空间ExcelAddInFunc
{ClassInterface(ClassInterfaceType.AutoDual)]
公共类fncAdd
{
> public fncAdd()
{
}
公共字符串__T()
{
字符串s ="测试" ;;
Excel .Application m_objExcel =
(Excel.Application)Marshal.GetActiveObject(" Excel.Application");
Excel.Worksheet ws =
(Excel.Worksheet)m_objExcel.ActiveWorkbook.ActiveS heet;
Excel.Range region =(Excel.Range)ws.Cells [10,10];
s = ws.Name.ToString(); //好的!
尝试
{/> region.Value2 =" qwe" ;; // bumm!
}
catch(例外e)
{
s = e.ToString();
}
返回s;
}
Hello,
I have made an small AddIn with udf for excel 2003.
I use vs2003.
The point of view is the function __T()
I call it in excel sheet writing =__T() [enter]
I am not able to set a value to a given cell.
region.Value2="qwe"; //bumm!
A exception will be trown. On all PCs with excel.
HRESULT 0x800A03EC
Is it com-registration problem?
But, it is possible to read the name of worksheet.
s=ws.Name.ToString(); //OK!
Who knows, what is the problem?
Thanks
microsoft.public.dotnet.languages.csharp
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Excel=Microsoft.Office.Interop.Excel; // ist nicht auf jedem
System. Nachinstallieren???
namespace ExcelAddInFunc
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class fncAdd
{
public fncAdd()
{
}
public string __T()
{
string s="Test";
Excel.Application m_objExcel =
(Excel.Application)Marshal.GetActiveObject("Excel. Application");
Excel.Worksheet ws =
(Excel.Worksheet)m_objExcel.ActiveWorkbook.ActiveS heet;
Excel.Range region=(Excel.Range)ws.Cells[10,10];
s=ws.Name.ToString(); //OK!
try
{
region.Value2="qwe"; //bumm!
}
catch(Exception e)
{
s=e.ToString();
}
return s;
}
}
applicationObject来自OnConnection ()或共享加载项
//获取活动工作表。
object sheet = applicationObject.GetType()。InvokeMember(" ActiveSheet",
BindingFlags.GetProperty,null,m_applicationObject,null);
//获取单元格J10
object range = sheet.GetType ()。InvokeMember(" Range",
BindingFlags.GetProperty,null,sheet,new object [] {" J10",Missing.Value}
);
//设置单元格J10的值
range.GetType()。InvokeMember(" Value",BindingFlags.SetProperty,null,>
range,new object [] {" Test"});
" Frank M. Walter"写道:
applicationObject is from OnConnection() or shared add-in
// Get the active worksheet.
object sheet = applicationObject.GetType().InvokeMember( "ActiveSheet",
BindingFlags.GetProperty, null, m_applicationObject, null );
// Get cell J10
object range = sheet.GetType().InvokeMember( "Range",
BindingFlags.GetProperty, null, sheet, new object[] { "J10", Missing.Value }
);
// Set the value of cell J10
range.GetType().InvokeMember( "Value", BindingFlags.SetProperty, null,
range, new object[] { "Test" } );
"Frank M. Walter" wrote:
您好,我已经为excel 2003用udf做了一个小的AddIn。
我使用vs2003。
关键点视图是函数__T()
我在excel表单中调用它= __ T()[输入]
我无法为给定单元格设置值。
region.Value2 =" qwe" ;; // bumm!
将播出一个例外。在所有具有excel的PC上。
HRESULT 0x800A03EC
是否有注册问题?
但是,可以读取工作表的名称。
s = ws.Name.ToString(); //好的!
谁知道,问题是什么?
谢谢
microsoft.public.dotnet.languages.csharp
使用System;
使用System.Runtime.InteropServices;
使用Microsoft.Win32;
使用Excel = Microsoft.Office.Interop.Excel; // ist nicht auf jedem系统。
Nachinstallieren ???
命名空间ExcelAddInFunc
{ClassInterface(ClassInterfaceType.AutoDual)]
公共类fncAdd
公共fncAdd()
{
}
公共字符串__T()
{
字符串s =" Test";
Excel.Application m_objExcel =
(Excel.Application)Marshal.GetActiveObject(" Excel.Application");
Excel.Worksheet ws =
(Excel.Worksheet)m_objExcel.ActiveWorkbook.ActiveS heet;
Excel.Range region =(Excel.Range)ws.Cells [10,10];
s = ws.Name.ToString (); //好的!
尝试
{/> region.Value2 =" qwe" ;; // bumm!
}
catch(例外e)
{
s = e.ToString();
}
返回s;
}
}
Hello,
I have made an small AddIn with udf for excel 2003.
I use vs2003.
The point of view is the function __T()
I call it in excel sheet writing =__T() [enter]
I am not able to set a value to a given cell.
region.Value2="qwe"; //bumm!
A exception will be trown. On all PCs with excel.
HRESULT 0x800A03EC
Is it com-registration problem?
But, it is possible to read the name of worksheet.
s=ws.Name.ToString(); //OK!
Who knows, what is the problem?
Thanks
microsoft.public.dotnet.languages.csharp
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Excel=Microsoft.Office.Interop.Excel; // ist nicht auf jedem System.
Nachinstallieren???
namespace ExcelAddInFunc
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class fncAdd
{
public fncAdd()
{
}
public string __T()
{
string s="Test";
Excel.Application m_objExcel =
(Excel.Application)Marshal.GetActiveObject("Excel. Application");
Excel.Worksheet ws =
(Excel.Worksheet)m_objExcel.ActiveWorkbook.ActiveS heet;
Excel.Range region=(Excel.Range)ws.Cells[10,10];
s=ws.Name.ToString(); //OK!
try
{
region.Value2="qwe"; //bumm!
}
catch(Exception e)
{
s=e.ToString();
}
return s;
}
}
这篇关于Excel:AddIn,填充活动表格单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!