Issues related to differences between c# version and vb.net version

15 views
Skip to first unread message

Ash Hui

unread,
Jul 20, 2024, 10:26:01 PM (2 days ago) Jul 20
to Excel-DNA
I recently tried to transplant the vb.net version of the dna project to c#. I encountered some questions during the transplantation process.

Question 1:
When registering, you only need to add PerformDefaultRegistration() in vb.net, and write ExcelRegistration.GetExcelFunctions().processParamsRegistrations().RegisterFunctions(); in c#.
Normally, the function names for the same function should be consistent.
I would like to ask if there are other places where the same function has different function names?

Question 2:
In vb.net,
Then import Microsoft.Office.Interop.Excel
Types from Excel can be used directly, e.g.
dim a as range

But in c#,
Use Microsoft.Office.Interop.Excel; after
When using the Range type, you must write out the complete library name (but when using the "Sheet" or "Application" type, you can use it directly)
Dim to Microsoft.Office.Interop.Excel.Range
Unless the library name is redefined as an alias at the beginning
I want to ask why range types are so special?

Question 3:
In the vb.net version, if you use the Register library to register a function, the range type can be directly supported in the UDF parameters, for example:
Function RangeToRef(rng As Range) As ExcelReference
But when I transplanted the same code to c# (also using the Register library):
static ExcelReference RangeToRef(Microsoft.Office.Interop.Excel.Range rng)
When opening the plug-in, an error will be reported:
Registration [Error] Method not registered due to unsupported signature: '<lambda>.xDown' : DnaMarshalException - Unknown Data Type: Microsoft.Office.Interop.Excel.Range

Is it true that in C#, we cannot directly define the parameter type as "Range" like in vb.net, but must define it as object or ExcelReference, and then convert it again inside the function.
Reply all
Reply to author
Forward
0 new messages