Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Unassigned: AddHostObject works very slowly [68]

$
0
0
Hi!
AddHostObject works very slowly for an object of type Microsoft.Office.Interop.Excel.Workbook.
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;

namespace ClearScriptTest
{
class Program
{
static void Main(string[] args)
{
Application ExcelApplication = null;
try
{
ExcelApplication = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch (COMException)
{
Type type = Type.GetTypeFromProgID("Excel.Application");
ExcelApplication = (Application)System.Activator.CreateInstance(type);
}
Workbook ExcelDocument = (Workbook)ExcelApplication.Workbooks.Add();
Microsoft.ClearScript.Windows.VBScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine();
engine.AddHostObject("ExcelObject", ExcelApplication);
engine.AddHostObject("DocumentObject", ExcelDocument); // Too long
engine.Execute(@"ExcelObject.ScreenUpdating = True
ExcelObject.Visible = True");
}
}
}
```
Can you please have a look?
Thanks!
Comments: OK, and when you say that the call takes too long, how long do you mean, approximately?

Viewing all articles
Browse latest Browse all 2297

Trending Articles