here is my code:
Expand|Select|Wrap|Line Numbers
- Dim ex As New Object
- Dim wb As Excel.Workbook
- Dim sheet As Excel.Worksheet
- 'create xls file and save into the specific path
- ex = CreateObject("Excel.Application")
- Dim wrkbook As Excel.Workbook
- wrkbook = ex.Workbooks.Open("C:\Inetpub\wwwroot\WWReport\Maxim.xls")
- sheet = wrkbook.Sheets(3)
my program should be generating an excel report. i have a template, and when i open the template (see code) the error occurs...
why is it occuring? i used late binding to create my Excel.Application Object...
this code works fine in office 2003, unfortunately, the company where im in is using office 2002, i am using either Microsoft excel object Library 10.0 or Microsoft.office.interop.excel.dll (which i downloaded from the internet "PIA") but either way, error still occurs wether i use excel object 10.0 or PIA.
Working with VB.Net 2003, Microsoft office 2002 (excel)
pls. help me out!
tnx a lot!
THE ERROR!!!
-------------------------------------------------------------
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 60: 'open the xls file after it has been saved
Line 61: Dim wrkbook As Excel.Workbook
Line 62: wrkbook = ex.Workbooks.Open("C:\Inetpub\wwwroot\WWReport\Max im.xls") ->this line is the source of the error
Line 63: sheet = wrkbook.Sheets(3)
Line 64:
Source File: C:\Inetpub\wwwroot\WWReport\GWHM.aspx.vb Line: 62
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
WWReport.GWHM.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\WWReport\GWHM.aspx.vb:62
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()