Quantcast
Channel: NetOffice - MS Office in .NET
Viewing all 1741 articles
Browse latest View live

Commented Unassigned: When to release event's COMObject? [21067]

$
0
0
When to release the newContentControl, DO I NEED to release it by myself, or NetOffice release it?

In the DocumentEvents2.cs
public void ContentControlOnExit([In, MarshalAs(UnmanagedType.IDispatch)] object contentControl, [In] [Out] ref object cancel)
{
Delegate[] recipients = _eventBinding.GetEventRecipients("ContentControlOnExit");
if( (true == _eventClass.IsCurrentlyDisposing) || (recipients.Length == 0) )
{
Invoker.ReleaseParamsArray(contentControl, cancel);
return;
}

NetOffice.WordApi.ContentControl newContentControl = NetOffice.Factory.CreateObjectFromComProxy(_eventClass, contentControl) as NetOffice.WordApi.ContentControl;
object[] paramsArray = new object[2];
paramsArray[0] = newContentControl;
paramsArray.SetValue(cancel, 1);
_eventBinding.RaiseCustomEvent("ContentControlOnExit", ref paramsArray);

cancel = (bool)paramsArray[1];
}
Comments: ** Comment from web user: SebastianDotNet **

the newContentControl is a child from _eventclass(may Word.Document) now in NO com proxy management.
(Dispose the document instance(_eventclass) means also to dispose all the childs *your turn.)

The common way is to dispose newContentControl at last in the event trigger to keep the memory usage low, otherwise newContentControl lives so long as the parent is alive.

*Sebastian


Commented Unassigned: When to release event's COMObject? [21067]

$
0
0
When to release the newContentControl, DO I NEED to release it by myself, or NetOffice release it?

In the DocumentEvents2.cs
public void ContentControlOnExit([In, MarshalAs(UnmanagedType.IDispatch)] object contentControl, [In] [Out] ref object cancel)
{
Delegate[] recipients = _eventBinding.GetEventRecipients("ContentControlOnExit");
if( (true == _eventClass.IsCurrentlyDisposing) || (recipients.Length == 0) )
{
Invoker.ReleaseParamsArray(contentControl, cancel);
return;
}

NetOffice.WordApi.ContentControl newContentControl = NetOffice.Factory.CreateObjectFromComProxy(_eventClass, contentControl) as NetOffice.WordApi.ContentControl;
object[] paramsArray = new object[2];
paramsArray[0] = newContentControl;
paramsArray.SetValue(cancel, 1);
_eventBinding.RaiseCustomEvent("ContentControlOnExit", ref paramsArray);

cancel = (bool)paramsArray[1];
}
Comments: ** Comment from web user: cgh_chen **

If have more ContentControlOnExit event handler, dispose the contentcontrol shoud be careful!

New Post: Creating COMM-add ins for the first time

$
0
0
I have VS2013 Premium version, installed NetOffice 1.6.0, not displaying project template NetOffice in VS2013 projects...any setting need to configure? Any help is appreciated.

Commented Unassigned: When to release event's COMObject? [21067]

$
0
0
When to release the newContentControl, DO I NEED to release it by myself, or NetOffice release it?

In the DocumentEvents2.cs
public void ContentControlOnExit([In, MarshalAs(UnmanagedType.IDispatch)] object contentControl, [In] [Out] ref object cancel)
{
Delegate[] recipients = _eventBinding.GetEventRecipients("ContentControlOnExit");
if( (true == _eventClass.IsCurrentlyDisposing) || (recipients.Length == 0) )
{
Invoker.ReleaseParamsArray(contentControl, cancel);
return;
}

NetOffice.WordApi.ContentControl newContentControl = NetOffice.Factory.CreateObjectFromComProxy(_eventClass, contentControl) as NetOffice.WordApi.ContentControl;
object[] paramsArray = new object[2];
paramsArray[0] = newContentControl;
paramsArray.SetValue(cancel, 1);
_eventBinding.RaiseCustomEvent("ContentControlOnExit", ref paramsArray);

cancel = (bool)paramsArray[1];
}
Comments: ** Comment from web user: cgh_chen **

2014-06-11 21:47:21,440 [1] DEBUG Change: 935 >> After start word with my AddIn ProxyCount = 935
Add Many COM Proxy from external code.

New Post: Creating COMM-add ins for the first time

$
0
0
Got it...it is just tab on Toolbox UI..I believe it is not integrated with Visual Studio..

Commented Unassigned: When to release event's COMObject? [21067]

$
0
0
When to release the newContentControl, DO I NEED to release it by myself, or NetOffice release it?

In the DocumentEvents2.cs
public void ContentControlOnExit([In, MarshalAs(UnmanagedType.IDispatch)] object contentControl, [In] [Out] ref object cancel)
{
Delegate[] recipients = _eventBinding.GetEventRecipients("ContentControlOnExit");
if( (true == _eventClass.IsCurrentlyDisposing) || (recipients.Length == 0) )
{
Invoker.ReleaseParamsArray(contentControl, cancel);
return;
}

NetOffice.WordApi.ContentControl newContentControl = NetOffice.Factory.CreateObjectFromComProxy(_eventClass, contentControl) as NetOffice.WordApi.ContentControl;
object[] paramsArray = new object[2];
paramsArray[0] = newContentControl;
paramsArray.SetValue(cancel, 1);
_eventBinding.RaiseCustomEvent("ContentControlOnExit", ref paramsArray);

cancel = (bool)paramsArray[1];
}
Comments: ** Comment from web user: cgh_chen **

Open Source Project, Debug find the error code !

Created Unassigned: How to return a COMObject In a Collection? [21075]

$
0
0
internal static bool TryGetCustumXMLPart(this Document doc, string namespaceURI, out CustomXMLPart checkedPart) {
checkedPart = null;
using (CustomXMLParts parts = doc.CustomXMLParts) {
foreach (CustomXMLPart part in doc.CustomXMLParts) {
string partNamespaceURI = part.NamespaceURI;
if (partNamespaceURI == namespaceURI) {
checkedPart = new CustomXMLPart(part); << ERROR
return true;
}
}
}
return false;
}

Commented Unassigned: How to return a COMObject In a Collection? [21075]

$
0
0
internal static bool TryGetCustumXMLPart(this Document doc, string namespaceURI, out CustomXMLPart checkedPart) {
checkedPart = null;
using (CustomXMLParts parts = doc.CustomXMLParts) {
foreach (CustomXMLPart part in doc.CustomXMLParts) {
string partNamespaceURI = part.NamespaceURI;
if (partNamespaceURI == namespaceURI) {
checkedPart = new CustomXMLPart(part); << ERROR
return true;
}
}
}
return false;
}
Comments: ** Comment from web user: panewman **

Did you try

```
part.ParentObject.RemoveChildObject(part);
```


New Post: Please speed up the COMObject create process!!

$
0
0
NetOffice cached the class type, I thank it can also cache the constructor.
_wrapperTypeCache.Add(fullClassName, classType);
                COMObject newClass = Activator.CreateInstance(classType, new object[] { caller, comProxy, comProxyType }) as COMObject;
                return newClass;
private static Type[] Params = new Type[] { typeof(string), typeof(string), typeof(string), typeof(XmlDocument) };
    internal void Register(Type type,  ElementNameAttribute att) {
        SpeedQName name = new SpeedQName(att.LocalName, att.NamespaceURI);
        var ctor = type.GetConstructor(Params);
        if (ctor != null) {
            DynamicMethod method = new DynamicMethod(string.Empty, type, Params);
            ILGenerator il = method.GetILGenerator();
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldarg_1);
            il.Emit(OpCodes.Ldarg_2);
            il.Emit(OpCodes.Ldarg_3);
            il.Emit(OpCodes.Newobj, ctor);
            il.Emit(OpCodes.Ret);
            Func<string, string, string, XbrlDocument, XbrlElement> fun = method.CreateDelegate(typeof(Func<string, string, string, XmlDocument, XmlElement>)) as Func<string, string, string, XmlDocument, XmlElement>;
            _qname2ImplType[name] = fun;
        }

    }

New Post: Please speed up the COMObject create process!!

$
0
0
I think It's most fast method to Create New Object. Activator.CreateInstance do more work at runtime.
In the Factory _globalObjectList can be ignore If user don't want it by Setting, OR it should only save (cache) the root COMObject, the child COMObject is disposed by the parent object

New Post: Application.Dispose

$
0
0
I think should Add a method to the NetOffice.Factory.Remove(COMObject), remove it from the COMObject List who is created and not disposed.

Commented Unassigned: How to return a COMObject In a Collection? [21075]

$
0
0
internal static bool TryGetCustumXMLPart(this Document doc, string namespaceURI, out CustomXMLPart checkedPart) {
checkedPart = null;
using (CustomXMLParts parts = doc.CustomXMLParts) {
foreach (CustomXMLPart part in doc.CustomXMLParts) {
string partNamespaceURI = part.NamespaceURI;
if (partNamespaceURI == namespaceURI) {
checkedPart = new CustomXMLPart(part); << ERROR
return true;
}
}
}
return false;
}
Comments: ** Comment from web user: cgh_chen **

internal static T Detach<T>(this T COMObj) where T : COMObject {
if (COMObj != null) {
COMObject p = COMObj.ParentObject;
if (p != null) {
p.RemoveChildObject(COMObj);
}
}
return COMObj;
}

New Post: Please speed up the COMObject create process!!

New Post: Open Word Document - passing in a binary array not physical file

$
0
0
Same here, would love to be able to open and save workbooks without them having to touch disk. Can someone gice some pointers on how this could be possible?

Created Unassigned: Excel Pivot Table SourceData Range >65536 Crashes [21086]

$
0
0
Hi Guys.

Running 1.6 and am trying to create a Pivot Table in Excel. I can get it to generate fine as long as the SourceData range does not go over 65536. If I go to 65537 I get:

```
{"Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"}
```

I assume there is a ushort variable limit to blame here? Here is the code that causes the problem (abbreviated to save space):

```
var workbook = ExcelApplication.ActiveWorkbook;
if (workbook == null)
return;

var DataWorksheet = (Worksheet)workbook.Worksheets.FirstOrDefault(ws => ((Worksheet)ws).Name == "Data");
if (DataWorksheet == null)
return;

var pivotsheet = workbook.Worksheets.Add() as Worksheet;
if (pivotsheet == null)
return;

// THE EVENTUAL PROBLEM WHEN > 65536
var usedrange = DataWorksheet.Range("A1:U65537");

//THIS LINE WILL CAUSE THE EXCEPTION WHEN usedrange IS > 65536
var pivotcache = workbook.PivotCaches().Add(XlPivotTableSourceType.xlDatabase, usedrange);

var pivottables = pivotsheet.PivotTables() as PivotTables;

if (pivottables != null)
{
var pivottable = pivottables.Add(pivotcache, pivotsheet.Range("A1"), "PivotTable1");
pivottable.InGridDropZones = false;
}
```

Thanks
Ernie

New Post: Identify workbooks after WorkbookActivateEvent

$
0
0
Hi Sebastian,

First off huge thanks for NetOffice! Extrmely good stuff!

I want to store extra data about workbooks, and select the right data when a user selects another workbook (to load into a taskpane). I have this code, but if I have two workbooks open and switch between then a couple of times, they get added to the List again every time, it seems the Wb reference points to a different object every time (some wrapper?).

Is there a way to uniquely identify a workbook after the WorkbookActivateEvent (Preferably without having to use the name as it may change) ?
XL.WorkbookActivateEvent += XL_WorkbookActivateEvent;
and handler:
List<Workbook> _workbooks = new List<Workbook>();

void XL_WorkbookActivateEvent(Workbook Wb) {
    if (!_workbooks.Contains(Wb)) { 
        // reference seem different every time event is fired
        _workbooks.Add(Wb);
        Wb.SheetChangeEvent += Wb_SheetChangeEvent;
    }
}

Created Unassigned: Detect NetOffice assembly OfficeApi. Type:SEHException Message:外部组件发生异常。 [21090]

$
0
0
IFactoryInfo:WordApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=4ce962cc9e5644e3:VBIDEApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=6040f8ab492f76a1
IFactoryInfo:OfficeApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=1208423a019d3443:VBIDEApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=6040f8ab492f76a1
IFactoryInfo:VBIDEApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=6040f8ab492f76a1:VBIDEApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=6040f8ab492f76a1
Attribute:System.Diagnostics.DebuggableAttribute
Attribute:System.Runtime.CompilerServices.RuntimeCompatibilityAttribute
Attribute:System.Reflection.AssemblyTitleAttribute
Attribute:System.Reflection.AssemblyDescriptionAttribute
Attribute:System.Reflection.AssemblyConfigurationAttribute
Attribute:System.Reflection.AssemblyCompanyAttribute
Attribute:System.Reflection.AssemblyProductAttribute
Attribute:System.Reflection.AssemblyCopyrightAttribute
Attribute:System.Reflection.AssemblyTrademarkAttribute
Attribute:System.Reflection.AssemblyFileVersionAttribute
NetOffice.Factory.Initialize() passed
NetOffice.Factory.Initialize() DeepLevel:True
Failed to resolve Assembly
Try to resolve Assembly
Failed to resolve Assembly
Failed to resolve Assembly
Failed to resolve Assembly
Failed to resolve Assembly
Failed to resolve Assembly
Detect NetOffice assembly OfficeApi.
Type:SEHException
Message:外部组件发生异常。
Target:System.RuntimeMethodHandle ResolveMethod(Int32, System.RuntimeTypeHandle*, Int32, System.RuntimeTypeHandle*, Int32)
Stack: 在 System.ModuleHandle.ResolveMethod(Int32 methodToken, RuntimeTypeHandle* typeInstArgs, Int32 typeInstCount, RuntimeTypeHandle* methodInstArgs, Int32 methodInstCount)
在 System.ModuleHandle.ResolveMethodHandle(Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
在 System.ModuleHandle.ResolveMethodHandle(Int32 methodToken)
在 System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, Module decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, RuntimeMethodHandle& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
在 System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
在 System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType)
在 System.Reflection.Assembly.GetCustomAttributes(Boolean inherit)
在 NetOffice.Factory.AddAssembly(String name, Assembly itemAssembly)
在 NetOffice.Factory.AddNetOfficeAssemblies(Boolean deepLevel)
在 NetOffice.Factory.Initialize()

Commented Unassigned: Detect NetOffice assembly OfficeApi. Type:SEHException Message:外部组件发生异常。 [21090]

$
0
0
IFactoryInfo:WordApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=4ce962cc9e5644e3:VBIDEApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=6040f8ab492f76a1
IFactoryInfo:OfficeApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=1208423a019d3443:VBIDEApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=6040f8ab492f76a1
IFactoryInfo:VBIDEApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=6040f8ab492f76a1:VBIDEApi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=6040f8ab492f76a1
Attribute:System.Diagnostics.DebuggableAttribute
Attribute:System.Runtime.CompilerServices.RuntimeCompatibilityAttribute
Attribute:System.Reflection.AssemblyTitleAttribute
Attribute:System.Reflection.AssemblyDescriptionAttribute
Attribute:System.Reflection.AssemblyConfigurationAttribute
Attribute:System.Reflection.AssemblyCompanyAttribute
Attribute:System.Reflection.AssemblyProductAttribute
Attribute:System.Reflection.AssemblyCopyrightAttribute
Attribute:System.Reflection.AssemblyTrademarkAttribute
Attribute:System.Reflection.AssemblyFileVersionAttribute
NetOffice.Factory.Initialize() passed
NetOffice.Factory.Initialize() DeepLevel:True
Failed to resolve Assembly
Try to resolve Assembly
Failed to resolve Assembly
Failed to resolve Assembly
Failed to resolve Assembly
Failed to resolve Assembly
Failed to resolve Assembly
Detect NetOffice assembly OfficeApi.
Type:SEHException
Message:外部组件发生异常。
Target:System.RuntimeMethodHandle ResolveMethod(Int32, System.RuntimeTypeHandle*, Int32, System.RuntimeTypeHandle*, Int32)
Stack: 在 System.ModuleHandle.ResolveMethod(Int32 methodToken, RuntimeTypeHandle* typeInstArgs, Int32 typeInstCount, RuntimeTypeHandle* methodInstArgs, Int32 methodInstCount)
在 System.ModuleHandle.ResolveMethodHandle(Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
在 System.ModuleHandle.ResolveMethodHandle(Int32 methodToken)
在 System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, Module decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, RuntimeMethodHandle& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
在 System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
在 System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType)
在 System.Reflection.Assembly.GetCustomAttributes(Boolean inherit)
在 NetOffice.Factory.AddAssembly(String name, Assembly itemAssembly)
在 NetOffice.Factory.AddNetOfficeAssemblies(Boolean deepLevel)
在 NetOffice.Factory.Initialize()
Comments: ** Comment from web user: SebastianDotNet **

i need more details or a sample solution to pin point the problem.
please send a sample solution to public.sebastian[at]web.de. (please include the NO assemblies)
*sebastian

New Post: Please speed up the COMObject create process!!

$
0
0
NO 1.7 use an option to disable the com proxy management by the way. (NetOffice.Settings)
Anyway, in fact you can't improve the method call performance in this way.(this works in .NET but not in COM. )
May its possible to improve performance in CreateProcess, (just for the second call, but most of the time you do this only at once)

*Sebastian

New Post: Cannot find the NetOffice equivalent for Microsoft.Office.Tools (.Excel.Controls)

$
0
0
Hi,

Is it possible to expand a bit more on this answer? Is it possible to learn more about what the tools namespace wrapper does?

I am trying to understand that if NetOffice doesn't support Tools namespace functionality directly, then how do I go about learning more details and do controls-related stuff without going through this wrapper.

Any relevant documentation / examples please?

Regards.
Viewing all 1741 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>