473,545 Members | 289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel Linksources / no object array enumerator

I'm having trouble iterating through LinkSources in an Excel workbook
using C#. I first wrote the below code in VBA to get a quick, correct
result,

Dim x As Variant
For Each x In ThisWorkbook.Li nkSources
Debug.Print x
Next

but am so far unable to successfully convert the code to workable
C# syntax. C#'s compiler complains

"foreach statement cannot operate on variables of type 'object'
because 'object' does not contain a definition for 'GetEnumerator' , or
it is inaccessible"

when I try to use the below code :

foreach(string Src in wb.LinkSources( rfl.Missing.Val ue)) {
Console.WriteLi ne(Src);
}

What can I do to list the links in a workbook from C#?

Thanks in advance,
Ali Tahbaz, MCSD
Nov 16 '05 #1
3 7533
have a look at this:
http://msdn.microsoft.com/library/de...l/excelobj.asp

Ajang (No MCSD)

"Ali Tahbaz" <ta*****@my-deja.com> wrote in message
news:e0******** *************** ***@posting.goo gle.com...
I'm having trouble iterating through LinkSources in an Excel workbook
using C#. I first wrote the below code in VBA to get a quick, correct
result,

Dim x As Variant
For Each x In ThisWorkbook.Li nkSources
Debug.Print x
Next

but am so far unable to successfully convert the code to workable
C# syntax. C#'s compiler complains

"foreach statement cannot operate on variables of type 'object'
because 'object' does not contain a definition for 'GetEnumerator' , or
it is inaccessible"

when I try to use the below code :

foreach(string Src in wb.LinkSources( rfl.Missing.Val ue)) {
Console.WriteLi ne(Src);
}

What can I do to list the links in a workbook from C#?

Thanks in advance,
Ali Tahbaz, MCSD

Nov 16 '05 #2
The link to a generic MS help file on .net+ Excel was interesting,
but has little to do with the specific question I asked. (There is no
reference to late bound object arrays returned to a C# client.)
Has anyone run into this problem and overcome it?

Ali

"arjang" <de*******@NOPS AMhotmail.com> wrote in message news:<eZ******* *******@TK2MSFT NGP12.phx.gbl>. ..
have a look at this:
http://msdn.microsoft.com/library/de...l/excelobj.asp

Ajang (No MCSD)

"Ali Tahbaz" <ta*****@my-deja.com> wrote in message
news:e0******** *************** ***@posting.goo gle.com...
I'm having trouble iterating through LinkSources in an Excel workbook
using C#. I first wrote the below code in VBA to get a quick, correct
result,

Dim x As Variant
For Each x In ThisWorkbook.Li nkSources
Debug.Print x
Next

but am so far unable to successfully convert the code to workable
C# syntax. C#'s compiler complains

"foreach statement cannot operate on variables of type 'object'
because 'object' does not contain a definition for 'GetEnumerator' , or
it is inaccessible"

when I try to use the below code :

foreach(string Src in wb.LinkSources( rfl.Missing.Val ue)) {
Console.WriteLi ne(Src);
}

What can I do to list the links in a workbook from C#?

Thanks in advance,
Ali Tahbaz, MCSD

Nov 16 '05 #3
For anyone else who needs to parse a variant array returned from Excel
or elsewhere, here is what I've found that works (through trial and error) :
(My specific problem was with returning the results of Excel's
LinkSources method.)

object src = (object)wb.Link Sources(Excel.X lLinkType.xlLin kTypeExcelLinks );
System.Array variantArray = (Array)src;
for(int i=1;i<=variantA rray.Length;i++ ) {
Console.WriteLi ne(variantArray .GetValue(i).To String());
}

C# likes to catch the variant array as a plain object type. Once you've
got the object type you can cast it to a System.Array and iterate through
the contained items.

Ali Tahbaz, MCSD

ta*****@my-deja.com (Ali Tahbaz) wrote in message news:<e0******* *************** ****@posting.go ogle.com>...
I'm having trouble iterating through LinkSources in an Excel workbook
using C#. I first wrote the below code in VBA to get a quick, correct
result,

Dim x As Variant
For Each x In ThisWorkbook.Li nkSources
Debug.Print x
Next

but am so far unable to successfully convert the code to workable
C# syntax. C#'s compiler complains

"foreach statement cannot operate on variables of type 'object'
because 'object' does not contain a definition for 'GetEnumerator' , or
it is inaccessible"

when I try to use the below code :

foreach(string Src in wb.LinkSources( rfl.Missing.Val ue)) {
Console.WriteLi ne(Src);
}

What can I do to list the links in a workbook from C#?

Thanks in advance,
Ali Tahbaz, MCSD

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2908
by: ghanley | last post by:
I have searched the web all day for a lead on this. I have found how to control the Graph object mut not the embedded excel unbound object frame. I am trying to chart the data below on one chart that comes from a query. I have managed to do this in excel and embedding the worksheet. Program 2005 2006 2007 2008 2009 2010
3
9139
by: Dent2 | last post by:
I wrote a nice C# excel routine to automate the formatting of some raw CSV data. I wrote the routine on a WinXP computer with Visual Studio .NET 2003 and Office XP installed. It compiled and ran on my XP machine without problems. Then, I tried to run the program on a Windows 2000 computer with Office 2000 installed. I got an error: ...
2
1165
by: Ginger | last post by:
Using VB.NET, I attempt to instanciate an Excel application object with the statement: Dim oExcelAppl As Excel.Application = New Excel.Applicatio I receive a runtime error with the message "Access is denied. Does anyone have a work-around ?
2
24450
by: George | last post by:
Is there a fast way to transfer an Excel range to an array? Example: Excel range is E2:E300 Dim person() as string Thanks, George
4
2503
by: msnnews.msn.com | last post by:
hi there, i've got a form that populates a datagrid, and a button that calls a function to export to an excel file. All is well with the export, no errors are returned, but the Excel instance doesnt want to terminate properly even when i set excelApp.Quit, and excelApp = nothing. has anyone else experienced a problem like this??? code...
2
2283
by: Larry Jones | last post by:
I want to place information from an active Excel spreadsheet to a VB.net form. I just want to place numbers from an Excel cell in a standard VB.net text box. Does anyone have sample code to demonstrate this process? I have tried coding the process myself without success. I have just purchased a 2003 version of VB.net and I am not sure if it is...
5
2760
by: RJN | last post by:
Hi I'm invoking the excel object from ASP.Net application. My development machine is Windows 2000 and MS Office is installed on my m/c. I have added reference to the Excel COM object, I have given Access and launch permissions to ASPNET user in DCOMCNFG and the identity set to launch user. But I get the following error, moment I try to...
4
1788
by: rjn | last post by:
Hi I'm invoking the excel object from ASP.Net application. My development machine is Windows 2000 and MS Office is installed on my m/c. I have added reference to the Excel COM object, I have given Access and launch permissions to ASPNET user in DCOMCNFG and the identity set to launch user. But I get the following error, moment I try to...
3
8082
by: dorlesky | last post by:
I've tried numerous times to get Excel to recognise the Excel Chart Object inserted into an Access Report. No Luck. I can get Access to start an instance of Excel, I can get Access to send the data to Excel. How do I get Excel to now Recognise the Chart object, so I can use Automation to change the features of the chart?
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7752
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5325
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.