Excel用户定义的函数锁调用电子表格 [英] Excel User Defined Function Locks Invoking Spreadsheet

查看:45
本文介绍了Excel用户定义的函数锁调用电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NetOffice编辑Excel电子表格.如果我从Excel用户定义函数中调用代码,则不会让我编辑调用电子表格.

  Excel.Application excelApplication = Excel.Application.GetActiveInstance();Excel.Worksheet workSheet =(Excel.Worksheet)excelApplication.ActiveSheet;Excel.Range单元格= workSheet.Cells [2,2];对象值= cell.Value;//作品cell.Value = 3;//引发异常 

有没有一种解决方法可以使我做到这一点?

例外是

"System.Runtime.InteropServices.COMException(0x80004005):有关详细信息,请参见内部异常.---> System.Reflection.TargetInvocationException:调用的目标已引发异常.--- System.Runtime.InteropServices.COMException:来自HRESULT的异常:0x800A03EC---内部异常堆栈跟踪的结尾---在System.RuntimeType.InvokeDispMethod(字符串名称,BindingFlags invokeAttr,对象目标,Object [] args,Boolean [] byrefModifiers,Int32文化,String [] namedParameters)在System.RuntimeType.InvokeMember处(字符串名称,BindingFlags bindingFlags,活页夹装订器,对象目标,Object []提供的Args,ParameterModifier []修饰符,CultureInfo文化,String []名为Params)在System.Type.InvokeMember(字符串名称,BindingFlags invokeAttr,活页夹装订器,对象目标,对象[] args,CultureInfo文化)在NetOffice.Invoker.PropertySet(COMObject comObject,字符串名称,Object []值)在NetOffice.Invoker.PropertySet(COMObject comObject,字符串名称,Object []值)在NetOffice.ExcelApi.Range.set_Value(对象值)在\ psf \ home \ Documents \ Visual Studio 2013 \ Projects \ Excel-REPL \ Excel-REPL \ Example01.cs中的ExcelExamplesCS45.Example01.RunExample()中:第29行在\ psf \ home \ Documents \ Visual Studio 2013 \ Projects \ Excel-REPL \ Excel-REPL \ MainClass.cs:line 310中的ClojureExcel.MainClass.Test()

解决方案

有一个非常简单的解决方法:只需在单独的线程中编辑工作表即可.我为什么不以为开始呢!

I am using NetOffice to edit an Excel Spreadsheet. If I call the code from an Excel user defined function it will not let me edit the invoking spreadsheet.

Excel.Application excelApplication = Excel.Application.GetActiveInstance();
Excel.Worksheet workSheet = (Excel.Worksheet) excelApplication.ActiveSheet;
Excel.Range cell = workSheet.Cells[2, 2];

object value = cell.Value; //works
cell.Value = 3; //Throws Exception

is there a workaround that will enable me to do this?

The exception is

"System.Runtime.InteropServices.COMException (0x80004005): See inner exception(s) for details. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture) at NetOffice.Invoker.PropertySet(COMObject comObject, String name, Object[] value) at NetOffice.Invoker.PropertySet(COMObject comObject, String name, Object[] value) at NetOffice.ExcelApi.Range.set_Value(Object value) at ExcelExamplesCS45.Example01.RunExample() in \psf\home\Documents\Visual Studio 2013\Projects\Excel-REPL\Excel-REPL\Example01.cs:line 29 at ClojureExcel.MainClass.Test() in \psf\home\Documents\Visual Studio 2013\Projects\Excel-REPL\Excel-REPL\MainClass.cs:line 310"

解决方案

There is a very simple workaround: simply edit the worksheet in a separate thread. Why didn't I think of it to begin with!!???

这篇关于Excel用户定义的函数锁调用电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆