Load .xls file into Excel


With below code, I can create a .xls file which has output of the specific listbox. It works.
However, I and trying to open the created file with Excel automatically.

Do you have any idea?

Dim Documents As FolderItem = SpecialFolder.ApplicationData

If Documents <> Nil Then

Dim ExcelOutputName As String
ExcelOutputName = "excelOut_temp.xls"

Dim f As FolderItem = Documents.Child(ExcelOutputName)

If f <> Nil Then
    Dim excelOut As TextOutputStream = TextOutputStream.Create(f)
    If excelOut <> nil then
      excelOut.Write DetailList.cell(-1,-1)
    End if
    excelOut = Nil
  Catch err As IOException
    MsgBox err.Message+". Error Code: "+Str(err.errorNumber) 
  End Try
End if

End If[/code]


Great! It works well.

May I get one more question?

Before calling f.launch, can we use below code?

Dim excel As New ExcelApplication

In fact, I have complex code for copying listbox to Excel worksheet but it looks very complex so I’m trying to write a text file and load it into Excel instead.
Here, I’m not sure I can use ‘AutoFit’ feature in my original code.

I think I can try to use below 2 lines instead of ‘f.launch’. With that, I am able to open the Excel file as well.
Let me try to use ‘excel.Cells.EntireColumn.AutoFit’.

        excel.Visible = true


        excel.Visible = true

Exception code 0: This command is unavailable because the license to use this application has expired., (failed on “AutoFit”)

I think there is a problem in Excel license of my system, after resolving that issue I will try it later.