cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Excel file

Former Member
0 Kudos

Hi Friends,

I need to open an excel file from Business partner form for that i created a button on that button click put the code .

My code for creating excel is ,

FileStream fs = new FileStream(sPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);

sPath is the file path.

I called the excel file using

ProcessStartInfo startInfo = new ProcessStartInfo(sPath);

startInfo.WindowStyle = ProcessWindowStyle.Minimized;

Process.Start(startInfo);

It shows the message as "unable to read file". Please help me to solve this problem.

Nisha.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi

If you need only to open file, your code is good.

Are you shure what file exist?

Make the brackpoint and see the sPath and try to open the file from command prompt.

Regards

Sierdna S.

P.S. VB code.


Private Sub LoadExcelFile(ByVal sXlsFile As String)
  Try
    Dim startInfo As New ProcessStartInfo(sXlsFile)
    startInfo.WindowStyle = ProcessWindowStyle.Maximized
    Process.Start(startInfo)
  Catch ex As Exception
    ' log exception
  Finally
    System.GC.Collect() 'Release the handle to the table 
  End Try
End Sub

Former Member
0 Kudos

Hi,

i am using 2003 excel

Nisha

Former Member
0 Kudos

Hi..

Ok try to add reference dll(excel).

Regards...

Billa 2007

Former Member
0 Kudos

Hi Billa 2007,

I tried the code

Dim sPath As String = CurDir()

Dim xlApp As Excel.Application = New Excel.Application

xlApp.Workbooks.Open(sPath & "\" & "XXXXX.xls")

having error

"The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)"

Nisha

Former Member
0 Kudos

hi

Add dll reference..

ur using 2007 or 2003 excel.

find in vb.net google ,example code also is there it self.

Regards..

Billa 2007

Former Member
0 Kudos

Hi...

Try this code..

Dim sPath As String = CurDir()

Dim xlApp As Excel.Application = New Excel.Application

xlApp.Workbooks.Open(sPath & "\" & "XXXXX.xls")

Regards..

Billa 2007