Re: How to open an excel file

Andrew Cherry <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <83FF4F4578524307AACCC2B46B4CC913@ghostwheel>
_Worksheets is the old interface, but it should still work.

The issue that jumps out at me is that you're querying the Sheets Collection for
a generic range without specifying a specific sheet.

Normally, to the best of my knowledge, you would either need to specify a
specific sheet in the string passed to get_Range(get_Range("Sheet1!A1")), or you
need to get a Worksheet first, then request a range.

HTH,
Andrew

-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps and
controls [mailto:[email protected]] On Behalf Of Vince P
Sent: Tuesday, March 20, 2007 8:10 PM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] How to open an excel file

Normally you want to interfaces for the objects... ie:

Sheets = (Microsoft.Office.Interop.Excel.IWorksheet)Workbook.Sheets
Or
Sheets = (Microsoft.Office.Interop.Excel.Worksheet)Workbook.Sheets

Whatever one is the Interface

-
THESE are the times that try men's souls. The summer soldier and the sunshine
patriot will, in this crisis, shrink from the service of their country; but he
that stands by it now, deserves the love and thanks of man and woman. Tyranny,
like hell, is not easily conquered; yet we have this consolation with us, that
the harder the conflict, the more glorious the triumph.


> -----Original Message-----
> From: Discussion forum for developers using Windows Forms to build
> apps and controls [mailto:[email protected]] On
> Behalf Of Steve Abaffy
> Sent: Monday, March 19, 2007 14:24
> To: [email protected]
> Subject: Re: [DOTNET-WINFORMS] How to open an excel file
>
> Ok that got me past that problem but I have new one. Here is the code:
>
> private Microsoft.Office.Interop.Excel._Application ExcelObj; private
> Microsoft.Office.Interop.Excel._Workbook Workbook; private
> Microsoft.Office.Interop.Excel._Worksheet Sheets; private
> Microsoft.Office.Interop.Excel.Range Range; private string filename;
>
> public string FileName { get { return filename; } set { filename =
> value; } }
>
> public string[] GetListValues()
> {
> ExcelObj = new Microsoft.Office.Interop.Excel.ApplicationClass();
> Workbook = ExcelObj.Workbooks.Open(filename, 0, false, 5, "", "",
> true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, ",", true,
> false, 0, true, true, false);
>
> Sheets = (Microsoft.Office.Interop.Excel._Worksheet)Workbook.Sheets;
> //Error
> Here
> Range = Sheets.get_Range("A1", "AZ1"); } This complies but errors out
> at the point shown
>
> What am I doing wrong, this really shouldn't this hard.
>
> -----Original Message-----
> From: Discussion forum for developers using Windows Forms to build
> apps and controls [mailto:[email protected]] On
> Behalf Of Patrick Steele
> Sent: Monday, March 19, 2007 1:56 PM
> To: [email protected]
> Subject: Re: [DOTNET-WINFORMS] How to open an excel file
>
> Usually on those interop assemblies, the "leading underscore" name
> represents the default COM interface.  That actuall class to
> instantiate is the name with "Class" appended on to it:
>
> _Application app = new ApplicationClass();
>
> --
> Patrick Steele
> http://weblogs.asp.net/psteele
>
>
>
> -----Original Message-----
> From: Discussion forum for developers using Windows Forms to build
> apps and controls [mailto:[email protected]] On
> Behalf Of Steve Abaffy
> Sent: Monday, March 19, 2007 2:48 PM
> To: [email protected]
> Subject: [DOTNET-WINFORMS] How to open an excel file
>
>
> Hello,
>
>
>         I have Microsoft.Office.Interop.Excel add as a Reference as
> well as Microsoft.Office.Core and I have the following line of code:
>
> private Microsoft.Office.Interop.Excel._Application ExcelObj; ExcelObj
> = new Microsoft.Office.Interop.Excel._Application();
>
> And I get the error
> Cannot create an instance of the abstract class or interface
> Microsoft.Office.Interop.Excel._Application
>
> What am I doing wrong???
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.