Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

I am trying to use Office Automation in my ASP.NET application using the Office XP PIAs.

 

This is the exception I gt when I try to create a workbook using the following code:

 

Try

Dim excel As Application = New Application

Dim wb As Workbook

Dim missing

 

wb = excel.Workbooks.Open("C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls")

excel.Visible = True

wb.Activate()

Catch ex As Exception

Dim strError As String = ex.Message

End Try

 

 

It raises an exception on the line where I open the workbook:

 

wb = excel.Workbooks.Open("C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls")

 

Kindly help.

 

THanks

Ashutosh

Posted

This is what I use to access an excel document using a winform. Hopefully it will give you some ideas.

 

       Dim objApp As Excel.Application
       Dim objBook As Excel._Workbook
       Dim objBooks As Excel.Workbooks
       Dim objSheets As Excel.Sheets
       Dim objSheet As Excel._Worksheet
       Dim range As Excel.Range

       Try
           objApp = New Excel.Application
           objBooks = objApp.Workbooks
           objBook = objBooks.Open(strExcelFile2Load)
           objSheets = objBook.Worksheets
           objSheet = CType(objSheets(1), Excel.Worksheet)

       Catch ex As Exception
           MessageBox.Show(ex.Message)
       End Try

 

Hope this helps

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted
This is what I use to access an excel document using a winform. Hopefully it will give you some ideas.

 

       Dim objApp As Excel.Application
       Dim objBook As Excel._Workbook
       Dim objBooks As Excel.Workbooks
       Dim objSheets As Excel.Sheets
       Dim objSheet As Excel._Worksheet
       Dim range As Excel.Range

       Try
           objApp = New Excel.Application
           objBooks = objApp.Workbooks
           objBook = objBooks.Open(strExcelFile2Load)
           objSheets = objBook.Worksheets
           objSheet = CType(objSheets(1), Excel.Worksheet)

       Catch ex As Exception
           MessageBox.Show(ex.Message)
       End Try

 

Hope this helps

 

 

I guess the above creates an instance of Excel Application which obviously I do not want to use.

 

Instead I am using Office XP PIAs and so if you look at my code its quite similiar to urs.

 

So I guess the line that raises the error is

objBook = objBooks.Open(strExcelFile2Load)

Posted

This code doesn't raise any errors. The strExcelFile2Load is defined earlier, this is the location of the file I wish to access.

 

Did you try using the above code and see if it opened the excel document for you?

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted
This code doesn't raise any errors. The strExcelFile2Load is defined earlier, this is the location of the file I wish to access.

 

Did you try using the above code and see if it opened the excel document for you?

 

 

Object Reference Not set to an instance of an object

 

on line

 

[color=Red]objBook = objBooks.Open(strExcelFile2Load)[/color]

Posted

dim strExcelFile2Load as string
strExcelFile2Load = "C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls"

 

I take it that you have defined strExcelFile2Load somewhere?

Have you added a reference to Excel?

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted
dim strExcelFile2Load as string
strExcelFile2Load = "C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls"

 

I take it that you have defined strExcelFile2Load somewhere?

Have you added a reference to Excel?

 

 

strExcelFile2Load has been defined. Not a problem

 

there is a reference to Excel. .............

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...