Re: How to open an excel file

Vince P <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <009601c76b66$6a72c090$3f5841b0$@net>
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.