Hi,
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?
[code]
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
Try
Dim excelOut As TextOutputStream = TextOutputStream.Create(f)
If excelOut <> nil then
excelOut.Write DetailList.cell(-1,-1)
excelOut.Close
End if
excelOut = Nil
Catch err As IOException
MsgBox err.Message+". Error Code: "+Str(err.errorNumber)
End Try
Else
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
excel.Cells.EntireColumn.AutoFit
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’.
'f.Launch
excel.Workbooks.Open(f.AbsolutePath)
excel.Visible = true
OLEException…Um…
'f.Launch
excel.Cells.EntireColumn.AutoFit
excel.Workbooks.Open(f.AbsolutePath)
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.
Thanks.