admin管理员组文章数量:1122832
I'm trying to create a unit test for a function that runs in a background worker from Excel. My unit test can start the background worker fine but when the BW completes we use ExcelAsyncUtil.QueueAsMacro from ExcelDNA to process the result. This works in the normal user flow fine
private void BW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{ // This is the worker thread-completed code
ExcelAsyncUtil.QueueAsMacro(() =>
{
string[] outputs = (string[])e.Result;
if (outputs.Length < 1)
{
MessageBox.Show("Unable to retrieve result", title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
Common.ExitToExcel();
return;
}
However if I run this from my unit test without the Excel window visible I get the following error:
ExcelDna.Integration.dll!ExcelDna.Integration.ExcelAsyncUtil.QueueAsMacro(ExcelDna.Integration.ExcelAction action) Unknown
Exception thrown: 'System.NullReferenceException' in ExcelDna.Integration.dll An unhandled exception of type 'System.NullReferenceException' occurred in ExcelDna.Integration.dll Object reference not set to an instance of an object.
Excel is being opened via the Excel Interop when this error occurs in test mode
xl.Application excelApp = new xl.Application(); //open an Excel application with the given workbook
xl.Workbook workbook = excelApp.Workbooks.Open(filepath);
Is there something I need to do here to initialise the ExcelDNA Integration correctly when Excel is started via the Interop and running without a visible GUI?
本文标签: cUsing ExcelAsyncUtilQueueAsMacro when Excel is only running for Comm automationStack Overflow
版权声明:本文标题:c# - Using ExcelAsyncUtil.QueueAsMacro when Excel is only running for Comm automation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304096a1932114.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论